From 76b1a8379b0e2dd51459fcbd8fa3121890dd9189 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Wed, 20 Feb 2019 19:14:42 -0330 Subject: [PATCH] webhooks/clubhouse: Support epic_archive events. --- .../clubhouse/fixtures/epic_archive.json | 21 +++++++++++++++++++ .../fixtures/story_comment_updated.json | 2 +- zerver/webhooks/clubhouse/tests.py | 5 +++++ zerver/webhooks/clubhouse/view.py | 12 ++++++----- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 zerver/webhooks/clubhouse/fixtures/epic_archive.json diff --git a/zerver/webhooks/clubhouse/fixtures/epic_archive.json b/zerver/webhooks/clubhouse/fixtures/epic_archive.json new file mode 100644 index 0000000000..07d02bc920 --- /dev/null +++ b/zerver/webhooks/clubhouse/fixtures/epic_archive.json @@ -0,0 +1,21 @@ +{ + "id":"5c6dd2b0-399b-43b9-9758-4d60771bad08", + "changed_at":"2019-02-20T22:20:32.285Z", + "primary_id":29, + "version":"v1", + "member_id":"5b1fda16-626f-487f-9ecf-f3a4abf42b8b", + "actions":[ + { + "id":29, + "entity_type":"epic", + "action":"update", + "name":"Zulip is epic!", + "changes":{ + "archived":{ + "new":true, + "old":false + } + } + } + ] +} diff --git a/zerver/webhooks/clubhouse/fixtures/story_comment_updated.json b/zerver/webhooks/clubhouse/fixtures/story_comment_updated.json index 70fb9d4365..0f45550737 100644 --- a/zerver/webhooks/clubhouse/fixtures/story_comment_updated.json +++ b/zerver/webhooks/clubhouse/fixtures/story_comment_updated.json @@ -28,4 +28,4 @@ "app_url":"https://app.clubhouse.io/zulip/story/11" } ] -} \ No newline at end of file +} diff --git a/zerver/webhooks/clubhouse/tests.py b/zerver/webhooks/clubhouse/tests.py index 11e865a96a..a6dc60b5e9 100644 --- a/zerver/webhooks/clubhouse/tests.py +++ b/zerver/webhooks/clubhouse/tests.py @@ -36,6 +36,11 @@ class ClubhouseWebhookTest(WebhookTestCase): expected_message = u"The story [Story 2](https://app.clubhouse.io/zulip/story/9) was archived." self.send_and_test_stream_message('story_archive', "Story 2", expected_message) + def test_epic_archive(self) -> None: + expected_message = u"The epic **Zulip is epic!** was archived." + self.send_and_test_stream_message('epic_archive', 'Zulip is epic!', + expected_message) + def test_story_unarchive(self) -> None: expected_message = u"The story [Story 2](https://app.clubhouse.io/zulip/story/9) was unarchived." self.send_and_test_stream_message('story_unarchive', "Story 2", expected_message) diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.py index bf9cb72aa7..b30db3d639 100644 --- a/zerver/webhooks/clubhouse/view.py +++ b/zerver/webhooks/clubhouse/view.py @@ -21,7 +21,7 @@ DESC_REMOVED_TEMPLATE = "Description for the {entity} {name_template} was remove STATE_CHANGED_TEMPLATE = "State of the {entity} {name_template} was changed from **{old}** to **{new}**." NAME_CHANGED_TEMPLATE = ("The name of the {entity} {name_template} was changed from:\n" "``` quote\n{old}\n```\nto\n``` quote\n{new}\n```") -STORY_ARCHIVED_TEMPLATE = "The story {name_template} was {action}." +ARCHIVED_TEMPLATE = "The {entity} {name_template} was {action}." STORY_TASK_TEMPLATE = "Task **{task_description}** was {action} the story {name_template}." STORY_TASK_COMPLETED_TEMPLATE = "Task **{task_description}** ({name_template}) was completed. :tada:" STORY_ADDED_REMOVED_EPIC_TEMPLATE = ("The story {story_name_template} was {action} the" @@ -210,7 +210,7 @@ def get_update_name_body(payload: Dict[str, Any], entity: str) -> str: return NAME_CHANGED_TEMPLATE.format(**kwargs) -def get_story_update_archived_body(payload: Dict[str, Any]) -> str: +def get_update_archived_body(payload: Dict[str, Any], entity: str) -> str: primary_action = get_action_with_primary_id(payload) archived = primary_action["changes"]["archived"] if archived["new"]: @@ -219,14 +219,15 @@ def get_story_update_archived_body(payload: Dict[str, Any]) -> str: action = "unarchived" kwargs = { - "name_template": STORY_NAME_TEMPLATE.format( + "entity": entity, + "name_template": get_name_template(entity).format( name=primary_action["name"], app_url=primary_action.get("app_url") ), "action": action, } - return STORY_ARCHIVED_TEMPLATE.format(**kwargs) + return ARCHIVED_TEMPLATE.format(**kwargs) def get_story_task_body(payload: Dict[str, Any], action: str) -> str: primary_action = get_action_with_primary_id(payload) @@ -473,7 +474,8 @@ def get_name_template(entity: str) -> str: return EPIC_NAME_TEMPLATE EVENT_BODY_FUNCTION_MAPPER = { - "story_update_archived": get_story_update_archived_body, + "story_update_archived": partial(get_update_archived_body, entity='story'), + "epic_update_archived": partial(get_update_archived_body, entity='epic'), "story_create": get_story_create_body, "pull-request_create": partial(get_story_create_github_entity_body, entity='pull-request'), "branch_create": partial(get_story_create_github_entity_body, entity='branch'),