webhooks/jira: Include issue title in messages.

This commit is contained in:
David Wood 2019-05-03 11:55:28 +01:00 committed by Eeshan Garg
parent 123bcea518
commit 16e9892ab2
2 changed files with 19 additions and 13 deletions

View File

@ -92,7 +92,7 @@ class JiraHookTests(WebhookTestCase):
def test_commented(self) -> None:
expected_topic = "BUG-15: New bug with hook"
expected_message = """Leo Franchi **added comment to** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
expected_message = """Leo Franchi **added comment to** [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
Adding a comment. Oh, what a comment it is!"""
@ -101,7 +101,7 @@ Adding a comment. Oh, what a comment it is!"""
def test_comment_edited(self) -> None:
expected_topic = "BUG-15: New bug with hook"
expected_message = """Leo Franchi **edited comment on** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
expected_message = """Leo Franchi **edited comment on** [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
Adding a comment. Oh, what a comment it is!"""
@ -109,24 +109,24 @@ Adding a comment. Oh, what a comment it is!"""
def test_comment_deleted(self) -> None:
expected_topic = "TOM-1: New Issue"
expected_message = "Tomasz Kolek **deleted comment from** [TOM-1](https://zuliptomek.atlassian.net/browse/TOM-1) (assigned to **kolaszek@go2.pl**)"
expected_message = "Tomasz Kolek **deleted comment from** [TOM-1: New Issue](https://zuliptomek.atlassian.net/browse/TOM-1) (assigned to **kolaszek@go2.pl**)"
self.send_and_test_stream_message('comment_deleted_v2', expected_topic, expected_message)
def test_commented_markup(self) -> None:
expected_topic = "TEST-7: Testing of rich text"
expected_message = """Leonardo Franchi [Administrator] **added comment to** [TEST-7](https://zulipp.atlassian.net/browse/TEST-7):\n\n\nThis is a comment that likes to **exercise** a lot of _different_ `conventions` that `jira uses`.\r\n\r\n~~~\n\r\nthis code is not highlighted, but monospaced\r\n\n~~~\r\n\r\n~~~\n\r\ndef python():\r\n print "likes to be formatted"\r\n\n~~~\r\n\r\n[http://www.google.com](http://www.google.com) is a bare link, and [Google](http://www.google.com) is given a title.\r\n\r\nThanks!\r\n\r\n~~~ quote\n\r\nSomeone said somewhere\r\n\n~~~"""
expected_message = """Leonardo Franchi [Administrator] **added comment to** [TEST-7: Testing of rich text](https://zulipp.atlassian.net/browse/TEST-7):\n\n\nThis is a comment that likes to **exercise** a lot of _different_ `conventions` that `jira uses`.\r\n\r\n~~~\n\r\nthis code is not highlighted, but monospaced\r\n\n~~~\r\n\r\n~~~\n\r\ndef python():\r\n print "likes to be formatted"\r\n\n~~~\r\n\r\n[http://www.google.com](http://www.google.com) is a bare link, and [Google](http://www.google.com) is given a title.\r\n\r\nThanks!\r\n\r\n~~~ quote\n\r\nSomeone said somewhere\r\n\n~~~"""
self.send_and_test_stream_message('commented_markup_v1', expected_topic, expected_message)
self.send_and_test_stream_message('commented_markup_v2', expected_topic, expected_message)
def test_deleted(self) -> None:
expected_topic = "BUG-15: New bug with hook"
expected_message = "Leo Franchi **deleted** [BUG-15](http://lfranchi.com:8080/browse/BUG-15)!"
expected_message = "Leo Franchi **deleted** [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15)!"
self.send_and_test_stream_message('deleted_v1', expected_topic, expected_message)
self.send_and_test_stream_message('deleted_v2', expected_topic, expected_message)
def test_reassigned(self) -> None:
expected_topic = "BUG-15: New bug with hook"
expected_message = """Leo Franchi **updated** [BUG-15](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
expected_message = """Leo Franchi **updated** [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**):
* Changed assignee to **Othello, the Moor of Venice**"""
self.send_and_test_stream_message('reassigned_v1', expected_topic, expected_message)
@ -134,7 +134,7 @@ Adding a comment. Oh, what a comment it is!"""
def test_priority_updated(self) -> None:
expected_topic = "TEST-1: Fix That"
expected_message = """Leonardo Franchi [Administrator] **updated** [TEST-1](https://zulipp.atlassian.net/browse/TEST-1) (assigned to **leo@zulip.com**):
expected_message = """Leonardo Franchi [Administrator] **updated** [TEST-1: Fix That](https://zulipp.atlassian.net/browse/TEST-1) (assigned to **leo@zulip.com**):
* Changed priority from **Critical** to **Major**"""
self.send_and_test_stream_message('updated_priority_v1', expected_topic, expected_message)
@ -142,7 +142,7 @@ Adding a comment. Oh, what a comment it is!"""
def test_status_changed(self) -> None:
expected_topic = "TEST-1: Fix That"
expected_message = """Leonardo Franchi [Administrator] **updated** [TEST-1](https://zulipp.atlassian.net/browse/TEST-1):
expected_message = """Leonardo Franchi [Administrator] **updated** [TEST-1: Fix That](https://zulipp.atlassian.net/browse/TEST-1):
* Changed status from **To Do** to **In Progress**"""
self.send_and_test_stream_message('change_status_v1', expected_topic, expected_message)

View File

@ -101,18 +101,23 @@ def get_in(payload: Dict[str, Any], keys: List[str], default: str='') -> Any:
return default
return payload
def get_issue_string(payload: Dict[str, Any], issue_id: Optional[str]=None) -> str:
def get_issue_string(payload: Dict[str, Any], issue_id: Optional[str]=None, with_title: bool=False) -> str:
# Guess the URL as it is not specified in the payload
# We assume that there is a /browse/BUG-### page
# from the REST url of the issue itself
if issue_id is None:
issue_id = get_issue_id(payload)
if with_title:
text = "{}: {}".format(issue_id, get_issue_title(payload))
else:
text = issue_id
base_url = re.match(r"(.*)\/rest\/api/.*", get_in(payload, ['issue', 'self']))
if base_url and len(base_url.groups()):
return u"[{}]({}/browse/{})".format(issue_id, base_url.group(1), issue_id)
return u"[{}]({}/browse/{})".format(text, base_url.group(1), issue_id)
else:
return issue_id
return text
def get_assignee_mention(assignee_email: str, realm: Realm) -> str:
if assignee_email != '':
@ -163,7 +168,7 @@ def handle_updated_issue_event(payload: Dict[str, Any], user_profile: UserProfil
# into this one 'updated' event type, so we try to extract the meaningful
# event that happened
issue_id = get_in(payload, ['issue', 'key'])
issue = get_issue_string(payload, issue_id)
issue = get_issue_string(payload, issue_id, True)
assignee_email = get_in(payload, ['issue', 'fields', 'assignee', 'emailAddress'], '')
assignee_mention = get_assignee_mention(assignee_email, user_profile.realm)
@ -230,7 +235,8 @@ def handle_created_issue_event(payload: Dict[str, Any], user_profile: UserProfil
)
def handle_deleted_issue_event(payload: Dict[str, Any], user_profile: UserProfile) -> str:
return u"{} **deleted** {}!".format(get_issue_author(payload), get_issue_string(payload))
return u"{} **deleted** {}!".format(
get_issue_author(payload), get_issue_string(payload, with_title=True))
JIRA_CONTENT_FUNCTION_MAPPER = {
"jira:issue_created": handle_created_issue_event,