mirror of https://github.com/zulip/zulip.git
jira: Handle comment_created events without issue details.
I'm not sure what causes some Jira webhook events to not include the metadata that other events do, but it's definitely a format sent by real installations of Jira (likely a very old version, since this has fields missing from what modern Jira does) and we've seen it in production. The best we can do is encourage users to upgrade Jira for better data.
This commit is contained in:
parent
180d8abed6
commit
6df86dab3e
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"timestamp": 1565964017153,
|
||||
"webhookEvent": "comment_created",
|
||||
"comment": {
|
||||
"self": "https://f20171170.atlassian.net/rest/api/2/issue/10000/comment/12000",
|
||||
"id": "12000",
|
||||
"author": {
|
||||
"self": "https://f20171170.atlassian.net/rest/api/2/user?accountId=5c76b994e1bcdf6294d0eb0f",
|
||||
"name": "admin",
|
||||
"key": "admin",
|
||||
"avatarUrls": {
|
||||
"48x48": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=48&s=48",
|
||||
"24x24": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=24&s=24",
|
||||
"16x16": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=16&s=16",
|
||||
"32x32": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=32&s=32"
|
||||
},
|
||||
"displayName": "Hemanth V. Alluri",
|
||||
"active": true,
|
||||
"timeZone": "Asia/Calcutta",
|
||||
},
|
||||
"body": "Sounds like it’s pretty important. I’ll get this fixed ASAP\\!",
|
||||
"updateAuthor": {
|
||||
"self": "https://f20171170.atlassian.net/rest/api/2/user?accountId=5c76b994e1bcdf6294d0eb0f",
|
||||
"name": "admin",
|
||||
"key": "admin",
|
||||
"avatarUrls": {
|
||||
"48x48": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=48&s=48",
|
||||
"24x24": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=24&s=24",
|
||||
"16x16": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=16&s=16",
|
||||
"32x32": "https://secure.gravatar.com/avatar/bc3f74559ceceb488f4189b7e7bdfec2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FHA-1.png&size=32&s=32"
|
||||
},
|
||||
"displayName": "Hemanth V. Alluri",
|
||||
"active": true,
|
||||
"timeZone": "Asia/Calcutta",
|
||||
},
|
||||
"created": "2019-08-16T19:30:17.153+0530",
|
||||
"updated": "2019-08-16T19:30:17.153+0530",
|
||||
},
|
||||
}
|
|
@ -196,6 +196,12 @@ Adding a comment. Oh, what a comment it is!
|
|||
expected_message = """Hemanth V. Alluri commented on issue: *"Add support for newer format Jira issue comment events"*\n``` quote\nSounds like it’s pretty important. I’ll get this fixed ASAP!\n```"""
|
||||
self.send_and_test_stream_message("comment_created", expected_topic, expected_message)
|
||||
|
||||
def test_comment_event_comment_created_no_issue_details(self) -> None:
|
||||
expected_topic = "10000: Upgrade Jira to get the issue title here."
|
||||
expected_message = """Hemanth V. Alluri commented on issue: *"Upgrade Jira to get the issue title here."*\n``` quote\nSounds like it’s pretty important. I’ll get this fixed ASAP!\n```"""
|
||||
self.send_and_test_stream_message("comment_created_no_issue_details",
|
||||
expected_topic, expected_message)
|
||||
|
||||
def test_comment_event_comment_edited(self) -> None:
|
||||
expected_topic = "SP-1: Add support for newer format Jira issue comment events"
|
||||
expected_message = """Hemanth V. Alluri updated their comment on issue: *"Add support for newer format Jira issue comment events"*\n``` quote\nThis is a very important issue! I’m on it!\n```"""
|
||||
|
|
|
@ -125,9 +125,27 @@ def get_issue_author(payload: Dict[str, Any]) -> str:
|
|||
return get_in(payload, ['user', 'displayName'])
|
||||
|
||||
def get_issue_id(payload: Dict[str, Any]) -> str:
|
||||
if 'issue' not in payload:
|
||||
# Some ancient version of Jira or one of its extensions posts
|
||||
# comment_created events without an "issue" element. For
|
||||
# these, the best we can do is extract the Jira-intenral
|
||||
# issue number and use that in the topic.
|
||||
#
|
||||
# Users who want better formatting can upgrade Jira.
|
||||
return payload['comment']['self'].split('/')[-3]
|
||||
|
||||
return get_in(payload, ['issue', 'key'])
|
||||
|
||||
def get_issue_title(payload: Dict[str, Any]) -> str:
|
||||
if 'issue' not in payload:
|
||||
# Some ancient version of Jira or one of its extensions posts
|
||||
# comment_created events without an "issue" element. For
|
||||
# these, the best we can do is extract the Jira-intenral
|
||||
# issue number and use that in the topic.
|
||||
#
|
||||
# Users who want better formatting can upgrade Jira.
|
||||
return 'Upgrade Jira to get the issue title here.'
|
||||
|
||||
return get_in(payload, ['issue', 'fields', 'summary'])
|
||||
|
||||
def get_issue_subject(payload: Dict[str, Any]) -> str:
|
||||
|
@ -253,10 +271,11 @@ def normalize_comment(comment: str) -> str:
|
|||
return normalized_comment
|
||||
|
||||
def handle_comment_created_event(payload: Dict[str, Any], user_profile: UserProfile) -> str:
|
||||
title = get_issue_title(payload)
|
||||
return "{author} commented on issue: *\"{title}\"\
|
||||
*\n``` quote\n{comment}\n```\n".format(
|
||||
author = payload["comment"]["author"]["displayName"],
|
||||
title = payload["issue"]["fields"]["summary"],
|
||||
title = title,
|
||||
comment = normalize_comment(payload["comment"]["body"])
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue