Skip to content

Commit

Permalink
Aggregate milestone change events
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Aug 2, 2020
1 parent ace9801 commit b2ab892
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions base-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ messages:
{% elif action == X_LABEL_AGGREGATE %} {{ templates.label_aggregation }}
{% elif action == MILESTONED %} added {{ templates.issue_link }} to {{ milestone_link(milestone) }}
{% elif action == DEMILESTONED %} removed {{ templates.issue_link }} from {{ milestone_link(milestone) }}
{% elif action == X_MILESTONE_CHANGED %} moved {{ templates.issue_link }} from {{ milestone_link(aggregation.from) }} to {{ milestone_link(aggregation.to) }}
{% elif action == ASSIGNED %} assigned {{ user_link(assignee) }} to
{% elif action == UNASSIGNED %} unassigned {{ user_link(assignee) }} from
{% else %} {{ action }}
Expand Down
1 change: 1 addition & 0 deletions github/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class IssueAction(SerializableEnum):
DEMILESTONED = "demilestoned"

X_LABEL_AGGREGATE = "xyz.maubot.issue_label_aggregation"
X_MILESTONE_CHANGED = "xyz.maubot.issue_milestone_changed"


@dataclass
Expand Down
20 changes: 19 additions & 1 deletion github/webhook/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,18 @@ def start_open_label_dropping(self) -> None:
else self.event.pull_request)
self._label_ids = {label.id for label in event_field.labels}

def start_milestone_aggregation(self) -> None:
if self.event.action == self.action_type.MILESTONED:
self.aggregation["to"] = self.event.milestone
elif self.event.action == self.action_type.DEMILESTONED:
self.aggregation["from"] = self.event.milestone

aggregation_starters: Dict[Tuple[EventType, Action], Callable] = {
(EventType.ISSUES, IssueAction.OPENED): start_open_label_dropping,
(EventType.ISSUES, IssueAction.LABELED): start_label_aggregation,
(EventType.ISSUES, IssueAction.UNLABELED): start_label_aggregation,
(EventType.ISSUES, IssueAction.MILESTONED): start_milestone_aggregation,
(EventType.ISSUES, IssueAction.DEMILESTONED): start_milestone_aggregation,
(EventType.PULL_REQUEST, PullRequestAction.OPENED): start_open_label_dropping,
(EventType.PULL_REQUEST, PullRequestAction.LABELED): start_label_aggregation,
(EventType.PULL_REQUEST, PullRequestAction.UNLABELED): start_label_aggregation,
Expand Down Expand Up @@ -119,6 +127,7 @@ async def _send(self) -> None:
self.delivery_ids, aggregation=self.aggregation)

def aggregate(self, evt_type: EventType, evt: Event, delivery_id: str) -> bool:
postpone = True
if (evt_type == EventType.ISSUES and self.event_type == EventType.ISSUE_COMMENT
and evt.action in (IssueAction.CLOSED, IssueAction.REOPENED)
and self.event.sender.id == evt.sender.id):
Expand Down Expand Up @@ -148,11 +157,20 @@ def aggregate(self, evt_type: EventType, evt: Event, delivery_id: str) -> bool:
self.aggregation["removed_labels"].append(evt.label)
else:
return False
elif self.event.action in (self.action_type.MILESTONED, self.action_type.DEMILESTONED):
if evt.action == self.action_type.MILESTONED:
self.aggregation["to"] = evt.milestone
elif evt.action == self.action_type.DEMILESTONED:
self.aggregation["from"] = evt.milestone
else:
return False
postpone = False
else:
return False
else:
return False

self.delivery_ids.add(delivery_id)
self.postpone.set()
if postpone:
self.postpone.set()
return True

0 comments on commit b2ab892

Please sign in to comment.