Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

webhooks/jira: Add test coverage for user mentions.

Niloth P988ed0498297
diff --git a/tools/test-backend b/tools/test-backend
index 9f87ac9a5f2..819d8936dad 100755
--- a/tools/test-backend
+++ b/tools/test-backend
@@ -122,7 +122,6 @@ not_yet_fully_covered = [
"zerver/data_import/import_util.py",
# Webhook integrations with incomplete coverage
"zerver/webhooks/greenhouse/view.py",
- "zerver/webhooks/jira/view.py",
"zerver/webhooks/teamcity/view.py",
"zerver/webhooks/travis/view.py",
"zerver/webhooks/zapier/view.py",
diff --git a/zerver/webhooks/jira/fixtures/comment_created.json b/zerver/webhooks/jira/fixtures/comment_created.json
index c95ca480d46..6ae008ff0af 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": "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}\\!",
+ "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}\\!\n[~Niloth]\n[~King Hamlet]",
"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.py
index 25eaf4ec6bf..e2806052783 100644
--- a/zerver/webhooks/jira/tests.py
+++ b/zerver/webhooks/jira/tests.py
@@ -105,7 +105,7 @@ Leonardo Franchi [Administrator] created [TEST-4: Test Created Assignee](https:/
def test_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\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```"""
+ 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**Niloth**\n@_**King Hamlet|10**\n```"""
self.check_webhook("comment_created", expected_topic_name, expected_message)
def test_comment_created_no_issue_details(self) -> None:
diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.py
index 03ee8d6b524..3ba01f9b1aa 100644
--- a/zerver/webhooks/jira/view.py
+++ b/zerver/webhooks/jira/view.py
@@ -9,6 +9,7 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.lib.exceptions import AnomalousWebhookPayloadError, UnsupportedWebhookEventTypeError
+from zerver.lib.mention import silent_mention_syntax_for_user
from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
from zerver.lib.validator import WildValue, check_none_or, check_string
@@ -87,7 +88,7 @@ def convert_jira_markup(content: str, realm: Realm) -> str:
# Try to look up username
user_profile = guess_zulip_user_from_jira(username, realm)
if user_profile:
- replacement = f"**{user_profile.full_name}**"
+ replacement = silent_mention_syntax_for_user(user_profile)
else:
replacement = f"**{username}**"
@@ -117,7 +118,7 @@ def get_issue_string(
if with_title:
text = f"{issue_id}: {get_issue_title(payload)}"
else:
- text = issue_id
+ text = issue_id # nocoverage
base_url = re.match(
r"(.*)\/rest\/api/.*", get_in(payload, ["issue", "self"]).tame(check_string)