From 2b87fa309847e52fbdf9aa37f179b47beb33e4b7 Mon Sep 17 00:00:00 2001 From: dgw Date: Fri, 10 May 2019 00:28:51 -0500 Subject: [PATCH] webhook: Handle milestone add/remove for issues/PRs Depends on helper functions added in #23. --- sopel_modules/github/formatting.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sopel_modules/github/formatting.py b/sopel_modules/github/formatting.py index 7d5bf10..1e8fa3a 100644 --- a/sopel_modules/github/formatting.py +++ b/sopel_modules/github/formatting.py @@ -257,6 +257,21 @@ def fmt_issue_label_message(payload=None): payload['issue']['number']) +def fmt_issue_milestone_message(payload=None): + if not payload: + payload = current_payload + added = payload['action'] == 'milestoned' + return '[{}] {} {} {} #{} {} the {} milestone'.format( + fmt_repo(payload['repository']['name']), + fmt_name(payload['sender']['login']), + 'added' if added else 'removed', + get_issue_type(payload), + get_issue_or_pr_number(payload), + 'to' if added else 'from', + payload['issue']['milestone']['title']) + + + def fmt_issue_comment_summary_message(payload=None): if not payload: payload = current_payload @@ -395,6 +410,8 @@ def get_formatted_response(payload, row): messages.append(fmt_issue_assignee_message() + " " + fmt_url(shorten_url(payload['issue']['html_url']))) elif re.match('(labeled|unlabeled)', payload['action']): messages.append(fmt_issue_label_message() + " " + fmt_url(shorten_url(payload['issue']['html_url']))) + elif re.match('(milestoned|demilestoned)', payload['action']): + messages.append(fmt_issue_milestone_message() + " " + fmt_url(shorten_url(payload['issue']['html_url']))) elif payload['event'] == 'issue_comment' and payload['action'] == 'created': messages.append(fmt_issue_comment_summary_message() + " " + fmt_url(shorten_url(payload['comment']['html_url']))) elif payload['event'] == 'gollum':