webhooks/clubhouse: Support epic_archive events.

This commit is contained in:
Eeshan Garg 2019-02-20 19:14:42 -03:30 committed by Tim Abbott
parent 51a1b76a1f
commit 76b1a8379b
4 changed files with 34 additions and 6 deletions

View File

@ -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
}
}
}
]
}

View File

@ -28,4 +28,4 @@
"app_url":"https://app.clubhouse.io/zulip/story/11" "app_url":"https://app.clubhouse.io/zulip/story/11"
} }
] ]
} }

View File

@ -36,6 +36,11 @@ class ClubhouseWebhookTest(WebhookTestCase):
expected_message = u"The story [Story 2](https://app.clubhouse.io/zulip/story/9) was archived." 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) 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: def test_story_unarchive(self) -> None:
expected_message = u"The story [Story 2](https://app.clubhouse.io/zulip/story/9) was unarchived." 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) self.send_and_test_stream_message('story_unarchive', "Story 2", expected_message)

View File

@ -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}**." 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" NAME_CHANGED_TEMPLATE = ("The name of the {entity} {name_template} was changed from:\n"
"``` quote\n{old}\n```\nto\n``` quote\n{new}\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_TEMPLATE = "Task **{task_description}** was {action} the story {name_template}."
STORY_TASK_COMPLETED_TEMPLATE = "Task **{task_description}** ({name_template}) was completed. :tada:" 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" 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) 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) primary_action = get_action_with_primary_id(payload)
archived = primary_action["changes"]["archived"] archived = primary_action["changes"]["archived"]
if archived["new"]: if archived["new"]:
@ -219,14 +219,15 @@ def get_story_update_archived_body(payload: Dict[str, Any]) -> str:
action = "unarchived" action = "unarchived"
kwargs = { kwargs = {
"name_template": STORY_NAME_TEMPLATE.format( "entity": entity,
"name_template": get_name_template(entity).format(
name=primary_action["name"], name=primary_action["name"],
app_url=primary_action.get("app_url") app_url=primary_action.get("app_url")
), ),
"action": action, "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: def get_story_task_body(payload: Dict[str, Any], action: str) -> str:
primary_action = get_action_with_primary_id(payload) primary_action = get_action_with_primary_id(payload)
@ -473,7 +474,8 @@ def get_name_template(entity: str) -> str:
return EPIC_NAME_TEMPLATE return EPIC_NAME_TEMPLATE
EVENT_BODY_FUNCTION_MAPPER = { 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, "story_create": get_story_create_body,
"pull-request_create": partial(get_story_create_github_entity_body, entity='pull-request'), "pull-request_create": partial(get_story_create_github_entity_body, entity='pull-request'),
"branch_create": partial(get_story_create_github_entity_body, entity='branch'), "branch_create": partial(get_story_create_github_entity_body, entity='branch'),