Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/jira: Apply Jira markup conversion for comment events.
Niloth P042d47066fa6
diff --git a/zerver/webhooks/jira/fixtures/comment_created.json b/zerver/webhooks/jira/fixtures/comment_created.jsonindex cc3cad88e67..c95ca480d46 100644--- a/zerver/webhooks/jira/fixtures/comment_created.json+++ b/zerver/webhooks/jira/fixtures/comment_created.json@@ -20,7 +20,7 @@"timeZone": "Asia/Calcutta","accountType": "atlassian"},- "body": "Sounds like it’s pretty important. I’ll get this fixed ASAP\\!",+ "body": "This is a comment that likes to *exercise* a lot of _different_ {{conventions}} that {{jira uses}}.\r\n\r\n{noformat}\r\nthis code is not highlighted, but monospaced\r\n{noformat}\r\n\r\n{code:python}\r\ndef python():\r\n print \"likes to be formatted\"\r\n{code}\r\n\r\n[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}\r\nSomeone said somewhere\r\n{quote}\\!","updateAuthor": {"self": "https://f20171170.atlassian.net/rest/api/2/user?accountId=5c76b994e1bcdf6294d0eb0f","name": "admin",diff --git a/zerver/webhooks/jira/tests.py b/zerver/webhooks/jira/tests.pyindex 2f08de1fcc4..a1fdac39b14 100644--- a/zerver/webhooks/jira/tests.py+++ b/zerver/webhooks/jira/tests.py@@ -151,7 +151,7 @@ Adding a comment. Oh, what a comment it is!def test_comment_event_comment_created(self) -> None:expected_topic_name = "SP-1: Add support for newer format Jira issue comment events"- expected_message = """Hemanth V. Alluri commented on [SP-1: Add support for newer format Jira issue comment events](https://f20171170.atlassian.net/browse/SP-1)\n``` quote\nSounds like it’s pretty important. I’ll get this fixed ASAP!\n```"""+ expected_message = """Hemanth V. Alluri commented on [SP-1: Add support for newer format Jira issue comment events](https://f20171170.atlassian.net/browse/SP-1)\n``` quote\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~~~!\n```"""self.check_webhook("comment_created", expected_topic_name, expected_message)def test_comment_event_comment_created_no_issue_details(self) -> None:diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.pyindex 691395caff5..7cac25e6d98 100644--- a/zerver/webhooks/jira/view.py+++ b/zerver/webhooks/jira/view.py@@ -44,6 +44,7 @@ def guess_zulip_user_from_jira(jira_username: str, realm: Realm) -> UserProfilereturn None+# https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=alldef convert_jira_markup(content: str, realm: Realm) -> str:# Attempt to do some simplistic conversion of Jira# formatting to Markdown, for consumption in Zulip@@ -276,7 +277,9 @@ def handle_deleted_issue_event(payload: WildValue, user_profile: UserProfile) ->)-def normalize_comment(comment: str) -> str:+def normalize_comment(comment: str, realm: Realm) -> str:+ comment = convert_jira_markup(comment, realm)+# Here's how Jira escapes special characters in their payload:# ,.?\\!\n\"'\n\\[]\\{}()\n@#$%^&*\n~`|/\\\\# for some reason, as of writing this, ! has two '\' before it.@@ -289,7 +292,9 @@ def handle_comment_created_event(payload: WildValue, user_profile: UserProfile)\n``` quote\n{comment}\n```\n".format(author=payload["comment"]["author"]["displayName"].tame(check_string),issue_string=get_issue_string(payload, with_title=True),- comment=normalize_comment(payload["comment"]["body"].tame(check_string)),+ comment=normalize_comment(+ payload["comment"]["body"].tame(check_string), user_profile.realm+ ),)@@ -298,7 +303,9 @@ def handle_comment_updated_event(payload: WildValue, user_profile: UserProfile)\n``` quote\n{comment}\n```\n".format(author=payload["comment"]["author"]["displayName"].tame(check_string),issue_string=get_issue_string(payload, with_title=True),- comment=normalize_comment(payload["comment"]["body"].tame(check_string)),+ comment=normalize_comment(+ payload["comment"]["body"].tame(check_string), user_profile.realm+ ),)@@ -307,7 +314,9 @@ def handle_comment_deleted_event(payload: WildValue, user_profile: UserProfile)\n``` quote\n~~{comment}~~\n```\n".format(author=payload["comment"]["author"]["displayName"].tame(check_string),issue_string=get_issue_string(payload, with_title=True),- comment=normalize_comment(payload["comment"]["body"].tame(check_string)),+ comment=normalize_comment(+ payload["comment"]["body"].tame(check_string), user_profile.realm+ ),)