Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Daily GitHub Summary Report -- UI improvements (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
alysivji authored Apr 19, 2020
1 parent a99cc89 commit bafa40a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
15 changes: 9 additions & 6 deletions busy_beaver/apps/github_integration/summary/blocks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from datetime import datetime
from datetime import datetime, timedelta
import logging
from typing import List, NamedTuple

from .summary import GitHubUserEvents
from busy_beaver.models import GitHubSummaryUser
from busy_beaver.toolbox.slack_block_kit import Divider, Section
from busy_beaver.toolbox.slack_block_kit.elements import Image

logger = logging.getLogger(__name__)

Expand All @@ -24,6 +25,7 @@ class GitHubSummaryPost:
def __init__(self, users: List[GitHubSummaryUser], boundary_dt: datetime):
self.users = users
self.boundary_dt = boundary_dt
self.now = boundary_dt + timedelta(days=1)

def __repr__(self): # pragma: no cover
return "<GitHubSummaryPost>"
Expand All @@ -40,17 +42,18 @@ def create(self):
self.all_user_events = all_user_events

def as_blocks(self):
output = [
Section(f"*Daily GitHub Summary -- {self.boundary_dt:%B %d, %Y}*"),
Divider(),
]
output = [Section(f"*Daily GitHub Summary -- {self.now:%B %d, %Y}*"), Divider()]

if not self.all_user_events:
output.append(Section(text="No activity to report."))
output.append(Divider())
return [block.to_dict() for block in output]

for user, events in self.all_user_events:
output.append(Section(text=events.generate_summary_text()))
profile_pic = (
f"https://avatars.githubusercontent.com/u/{user.github_id}?size=75"
)
img = Image(image_url=profile_pic, alt_text=f"{user.github_username}")
output.append(Section(text=events.generate_summary_text(), accessory=img))
output.append(Divider())
return [block.to_dict() for block in output]
6 changes: 3 additions & 3 deletions busy_beaver/apps/github_integration/summary/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def __init__(self, user: GitHubSummaryUser, boundary_dt: datetime):
StarredReposList(),
]

username = user.github_username
self.username = user.github_username
start_dt = boundary_dt
end_dt = start_dt + timedelta(days=1) # TODO depends on cadence
end_dt = start_dt + timedelta(days=1)

timeline = github.user_activity_during_range(username, start_dt, end_dt)
timeline = github.user_activity_during_range(self.username, start_dt, end_dt)
for event in timeline:
for event_list in self.event_lists:
if event_list.matches_event(event):
Expand Down
6 changes: 5 additions & 1 deletion busy_beaver/toolbox/slack_block_kit/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- https://api.slack.com/block-kit
- https://api.slack.com/tools/block-kit-builder
"""
from .elements import Element


class Block:
Expand Down Expand Up @@ -139,7 +140,10 @@ class Section(Block):

type = "section"

def __init__(self, text: str, block_id: str = ""):
def __init__(self, text: str, *, block_id: str = "", accessory: Element = None):
super().__init__(block_id)
self.output["type"] = self.type
self.output["text"] = {"type": "mrkdwn", "text": text}

if accessory:
self.output["accessory"] = accessory.to_dict()
32 changes: 32 additions & 0 deletions busy_beaver/toolbox/slack_block_kit/elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Slack Block Kit: Block Elements
Block elements can be used inside of section, context, and actions
layout blocks. Inputs can only be used inside of input blocks.
https://api.slack.com/reference/block-kit/block-elements
"""


class Element:
type = None

def __init__(self):
self.output = {}
self.output["type"] = self.type

def __repr__(self): # pragma: no cover
cls_name = self.__class__.__name__
return f"<{cls_name}>"

def to_dict(self) -> dict:
return self.output


class Image(Element):
type = "image"

def __init__(self, image_url, alt_text):
super().__init__()
self.output["image_url"] = image_url
self.output["alt_text"] = alt_text

0 comments on commit bafa40a

Please sign in to comment.