diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py index 1de114012c..9c17b5eb19 100644 --- a/zerver/lib/webhooks/git.py +++ b/zerver/lib/webhooks/git.py @@ -20,7 +20,7 @@ PUSH_COMMITS_MESSAGE_TEMPLATE = u"""{user_name} {pushed_text} to branch {branch_ FORCE_PUSH_COMMITS_MESSAGE_TEMPLATE = u"{user_name} [force pushed]({url}) to branch {branch_name}. Head is now {head}" REMOVE_BRANCH_MESSAGE_TEMPLATE = u"{user_name} deleted branch {branch_name}" -PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE = u"{user_name} {action} [{type}]({url})" +PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE = u"{user_name} {action} [{type}{id}]({url})" PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE = u"(assigned to {assignee})" PULL_REQUEST_BRANCH_INFO_TEMPLATE = u"\nfrom `{target}` to `{base}`" PULL_REQUEST_OR_ISSUE_CONTENT_MESSAGE_TEMPLATE = u"\n~~~ quote\n{message}\n~~~" @@ -56,16 +56,17 @@ def get_remove_branch_event_message(user_name, branch_name): ) def get_pull_request_event_message( - user_name, action, url, + user_name, action, url, number=None, target_branch=None, base_branch=None, message=None, assignee=None, type='PR' ): - # type: (text_type, text_type, text_type, Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type]) -> text_type + # type: (text_type, text_type, text_type, Optional[int], Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type], Optional[text_type]) -> text_type main_message = PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE.format( user_name=user_name, action=action, type=type, - url=url + url=url, + id=" #{}".format(number) if number is not None else '' ) if assignee: main_message += PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignee) @@ -79,12 +80,13 @@ def get_pull_request_event_message( main_message += '\n' + PULL_REQUEST_OR_ISSUE_CONTENT_MESSAGE_TEMPLATE.format(message=message) return main_message.rstrip() -def get_issue_event_message(user_name, action, url, message=None, assignee=None): - # type: (text_type, text_type, text_type, Optional[text_type], Optional[text_type]) -> text_type +def get_issue_event_message(user_name, action, url, number=None, message=None, assignee=None): + # type: (text_type, text_type, text_type, Optional[int], Optional[text_type], Optional[text_type]) -> text_type return get_pull_request_event_message( user_name, action, url, + number, message=message, assignee=assignee, type='Issue' diff --git a/zerver/tests/webhooks/test_bitbucket.py b/zerver/tests/webhooks/test_bitbucket.py index 9f84e14277..20f1fb2706 100644 --- a/zerver/tests/webhooks/test_bitbucket.py +++ b/zerver/tests/webhooks/test_bitbucket.py @@ -56,22 +56,22 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_issue_created_event(self): # type: () -> None - expected_message = u"kolaszek created [Issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)(assigned to kolaszek)\n\n~~~ quote\nSuch a bug\n~~~" + expected_message = u"kolaszek created [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)(assigned to kolaszek)\n\n~~~ quote\nSuch a bug\n~~~" self.send_and_test_stream_message('v2_issue_created', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message) def test_bitbucket2_on_issue_updated_event(self): # type: () -> None - expected_message = u"kolaszek updated [Issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)" + expected_message = u"kolaszek updated [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)" self.send_and_test_stream_message('v2_issue_updated', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message) def test_bitbucket2_on_issue_commented_event(self): # type: () -> None - expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/issues/2#comment-28973596) on [Issue](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)" + expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/issues/2#comment-28973596) on [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)" self.send_and_test_stream_message('v2_issue_commented', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message) def test_bitbucket2_on_pull_request_created_event(self): # type: () -> None - expected_message = u"kolaszek created [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)(assigned to tkolek)\nfrom `new-branch` to `master`\n\n~~~ quote\ndescription\n~~~" + expected_message = u"kolaszek created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)(assigned to tkolek)\nfrom `new-branch` to `master`\n\n~~~ quote\ndescription\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:created' } @@ -79,7 +79,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_updated_event(self): # type: () -> None - expected_message = u"kolaszek updated [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)(assigned to tkolek)\nfrom `new-branch` to `master`\n\n~~~ quote\ndescription\n~~~" + expected_message = u"kolaszek updated [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)(assigned to tkolek)\nfrom `new-branch` to `master`\n\n~~~ quote\ndescription\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:updated' } @@ -87,7 +87,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_approved_event(self): # type: () -> None - expected_message = u"kolaszek approved [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" + expected_message = u"kolaszek approved [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:approved' } @@ -95,7 +95,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_unapproved_event(self): # type: () -> None - expected_message = u"kolaszek unapproved [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" + expected_message = u"kolaszek unapproved [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:unapproved' } @@ -103,7 +103,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_declined_event(self): # type: () -> None - expected_message = u"kolaszek rejected [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" + expected_message = u"kolaszek rejected [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:rejected' } @@ -111,7 +111,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_merged_event(self): # type: () -> None - expected_message = u"kolaszek merged [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" + expected_message = u"kolaszek merged [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:merged' } @@ -119,7 +119,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_comment_created_event(self): # type: () -> None - expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/3)\n\n~~~ quote\nComment1\n~~~" + expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3)\n\n~~~ quote\nComment1\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:comment_created' } @@ -127,7 +127,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_comment_updated_event(self): # type: () -> None - expected_message = u"kolaszek updated [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/3)\n\n~~~ quote\nComment1\n~~~" + expected_message = u"kolaszek updated [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3)\n\n~~~ quote\nComment1\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:comment_updated' } @@ -135,7 +135,7 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_comment_deleted_event(self): # type: () -> None - expected_message = u"kolaszek deleted [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR](https://bitbucket.org/kolaszek/repository-name/pull-requests/3)\n\n~~~ quote\nComment1\n~~~" + expected_message = u"kolaszek deleted [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3)\n\n~~~ quote\nComment1\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:comment_deleted' } diff --git a/zerver/tests/webhooks/test_github.py b/zerver/tests/webhooks/test_github.py index 659de21a17..4d37a4d518 100644 --- a/zerver/tests/webhooks/test_github.py +++ b/zerver/tests/webhooks/test_github.py @@ -89,49 +89,49 @@ class GithubV1HookTests(WebhookTestCase): # type: () -> None self.basic_test('issues_opened', 'issues', "zulip-test / Issue #5 The frobnicator doesn't work", - "zbenjamin opened [Issue](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nI tried changing the widgets, but I got:\r\n\r\nPermission denied: widgets are immutable\n~~~") + "zbenjamin opened [Issue #5](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nI tried changing the widgets, but I got:\r\n\r\nPermission denied: widgets are immutable\n~~~") def test_issue_comment(self): # type: () -> None self.basic_test('issue_comment', 'issues', "zulip-test / Issue #5 The frobnicator doesn't work", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) on [Issue](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~") + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) on [Issue #5](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~") def test_issues_closed(self): # type: () -> None self.basic_test('issues_closed', 'issues', "zulip-test / Issue #5 The frobnicator doesn't work", - "zbenjamin closed [Issue](https://github.com/zbenjamin/zulip-test/issues/5)") + "zbenjamin closed [Issue #5](https://github.com/zbenjamin/zulip-test/issues/5)") def test_pull_request_opened(self): # type: () -> None self.basic_test('pull_request_opened', 'commits', "zulip-test / PR #7 Counting is hard.", - "lfaraone opened [PR](https://github.com/zbenjamin/zulip-test/pull/7)(assigned to lfaraone)\nfrom `patch-2` to `master`\n\n~~~ quote\nOmitted something I think?\n~~~") + "lfaraone opened [PR #7](https://github.com/zbenjamin/zulip-test/pull/7)(assigned to lfaraone)\nfrom `patch-2` to `master`\n\n~~~ quote\nOmitted something I think?\n~~~") def test_pull_request_closed(self): # type: () -> None self.basic_test('pull_request_closed', 'commits', "zulip-test / PR #7 Counting is hard.", - "zbenjamin closed [PR](https://github.com/zbenjamin/zulip-test/pull/7)") + "zbenjamin closed [PR #7](https://github.com/zbenjamin/zulip-test/pull/7)") def test_pull_request_synchronize(self): # type: () -> None self.basic_test('pull_request_synchronize', 'commits', "zulip-test / PR #13 Even more cowbell.", - "zbenjamin synchronized [PR](https://github.com/zbenjamin/zulip-test/pull/13)") + "zbenjamin synchronized [PR #13](https://github.com/zbenjamin/zulip-test/pull/13)") def test_pull_request_comment(self): # type: () -> None self.basic_test('pull_request_comment', 'commits', "zulip-test / PR #9 Less cowbell.", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~") + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR #9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~") def test_pull_request_comment_user_specified_stream(self): # type: () -> None self.basic_test('pull_request_comment', 'my_commits', "zulip-test / PR #9 Less cowbell.", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~", + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR #9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~", send_stream=True) def test_commit_comment(self): @@ -230,50 +230,50 @@ class GithubV2HookTests(WebhookTestCase): # type: () -> None self.basic_test('issues_opened', 'issues', "zulip-test / Issue #5 The frobnicator doesn't work", - "zbenjamin opened [Issue](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nI tried changing the widgets, but I got:\r\n\r\nPermission denied: widgets are immutable\n~~~") + "zbenjamin opened [Issue #5](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nI tried changing the widgets, but I got:\r\n\r\nPermission denied: widgets are immutable\n~~~") def test_issue_comment(self): # type: () -> None self.basic_test('issue_comment', 'issues', "zulip-test / Issue #5 The frobnicator doesn't work", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) on [Issue](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~") + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/issues/5#issuecomment-23374280) on [Issue #5](https://github.com/zbenjamin/zulip-test/issues/5)\n\n~~~ quote\nWhoops, I did something wrong.\r\n\r\nI'm sorry.\n~~~") def test_issues_closed(self): # type: () -> None self.basic_test('issues_closed', 'issues', "zulip-test / Issue #5 The frobnicator doesn't work", - "zbenjamin closed [Issue](https://github.com/zbenjamin/zulip-test/issues/5)") + "zbenjamin closed [Issue #5](https://github.com/zbenjamin/zulip-test/issues/5)") def test_pull_request_opened(self): # type: () -> None self.basic_test('pull_request_opened', 'commits', "zulip-test / PR #7 Counting is hard.", - "lfaraone opened [PR](https://github.com/zbenjamin/zulip-test/pull/7)(assigned to lfaraone)\nfrom `patch-2` to `master`\n\n~~~ quote\nOmitted something I think?\n~~~") + "lfaraone opened [PR #7](https://github.com/zbenjamin/zulip-test/pull/7)(assigned to lfaraone)\nfrom `patch-2` to `master`\n\n~~~ quote\nOmitted something I think?\n~~~") def test_pull_request_closed(self): # type: () -> None self.basic_test('pull_request_closed', 'commits', "zulip-test / PR #7 Counting is hard.", - "zbenjamin closed [PR](https://github.com/zbenjamin/zulip-test/pull/7)") + "zbenjamin closed [PR #7](https://github.com/zbenjamin/zulip-test/pull/7)") def test_pull_request_synchronize(self): # type: () -> None self.basic_test('pull_request_synchronize', 'commits', "zulip-test / PR #13 Even more cowbell.", - "zbenjamin synchronized [PR](https://github.com/zbenjamin/zulip-test/pull/13)") + "zbenjamin synchronized [PR #13](https://github.com/zbenjamin/zulip-test/pull/13)") def test_pull_request_comment(self): # type: () -> None self.basic_test('pull_request_comment', 'commits', "zulip-test / PR #9 Less cowbell.", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~") + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR #9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~") def test_pull_request_comment_user_specified_stream(self): # type: () -> None self.basic_test('pull_request_comment', 'my_commits', "zulip-test / PR #9 Less cowbell.", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~", + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/pull/9#issuecomment-24771110) on [PR #9](https://github.com/zbenjamin/zulip-test/pull/9)\n\n~~~ quote\nYeah, who really needs more cowbell than we already have?\n~~~", send_stream=True) def test_commit_comment(self): diff --git a/zerver/tests/webhooks/test_gitlab.py b/zerver/tests/webhooks/test_gitlab.py index 53bc597cff..8387b97e09 100644 --- a/zerver/tests/webhooks/test_gitlab.py +++ b/zerver/tests/webhooks/test_gitlab.py @@ -57,7 +57,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_without_assignee_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / Issue #1 Issue title" - expected_message = u"Tomasz Kolek created [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)\n\n~~~ quote\nIssue description\n~~~" + expected_message = u"Tomasz Kolek created [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)\n\n~~~ quote\nIssue description\n~~~" self.send_and_test_stream_message( 'issue_created_without_assignee', @@ -69,7 +69,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_assignee_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / Issue #1 Issue title" - expected_message = u"Tomasz Kolek created [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)(assigned to Tomasz Kolek)\n\n~~~ quote\nIssue description\n~~~" + expected_message = u"Tomasz Kolek created [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)(assigned to Tomasz Kolek)\n\n~~~ quote\nIssue description\n~~~" self.send_and_test_stream_message( 'issue_created_with_assignee', @@ -81,7 +81,7 @@ class GitlabHookTests(WebhookTestCase): def test_update_issue_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / Issue #1 Issue title_new" - expected_message = u"Tomasz Kolek updated [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)" + expected_message = u"Tomasz Kolek updated [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)" self.send_and_test_stream_message( 'issue_updated', @@ -93,7 +93,7 @@ class GitlabHookTests(WebhookTestCase): def test_close_issue_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / Issue #1 Issue title_new" - expected_message = u"Tomasz Kolek closed [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)" + expected_message = u"Tomasz Kolek closed [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)" self.send_and_test_stream_message( 'issue_closed', @@ -105,7 +105,7 @@ class GitlabHookTests(WebhookTestCase): def test_reopen_issue_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / Issue #1 Issue title_new" - expected_message = u"Tomasz Kolek reopened [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)" + expected_message = u"Tomasz Kolek reopened [Issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)" self.send_and_test_stream_message( 'issue_reopened', @@ -129,7 +129,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_merge_request_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / MR #1 Tomek" - expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1#note_14171860) on [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1)\n\n~~~ quote\nNice merge request!\n~~~" + expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1#note_14171860) on [MR #1](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1)\n\n~~~ quote\nNice merge request!\n~~~" self.send_and_test_stream_message( 'merge_request_note', @@ -141,7 +141,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_issue_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / Issue #2 abc" - expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2#note_14172057) on [Issue](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2)\n\n~~~ quote\nNice issue\n~~~" + expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2#note_14172057) on [Issue #2](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2)\n\n~~~ quote\nNice issue\n~~~" self.send_and_test_stream_message( 'issue_note', @@ -153,7 +153,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_snippet_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / Snippet #2 test" - expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [Snippet](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2)\n\n~~~ quote\nNice snippet\n~~~" + expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [Snippet #2](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2)\n\n~~~ quote\nNice snippet\n~~~" self.send_and_test_stream_message( 'snippet_note', @@ -165,7 +165,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_created_without_assignee_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / MR #2 NEW MR" - expected_message = u"Tomasz Kolek created [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)\nfrom `tomek` to `master`\n\n~~~ quote\ndescription of merge request\n~~~" + expected_message = u"Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)\nfrom `tomek` to `master`\n\n~~~ quote\ndescription of merge request\n~~~" self.send_and_test_stream_message( 'merge_request_created_without_assignee', @@ -176,7 +176,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_created_with_assignee_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / MR #3 New Merge Request" - expected_message = u"Tomasz Kolek created [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to Tomasz Kolek)\nfrom `tomek` to `master`\n\n~~~ quote\ndescription of merge request\n~~~" + expected_message = u"Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to Tomasz Kolek)\nfrom `tomek` to `master`\n\n~~~ quote\ndescription of merge request\n~~~" self.send_and_test_stream_message( 'merge_request_created_with_assignee', expected_subject, @@ -187,7 +187,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_closed_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / MR #2 NEW MR" - expected_message = u"Tomasz Kolek closed [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)" + expected_message = u"Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)" self.send_and_test_stream_message( 'merge_request_closed', @@ -199,7 +199,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_updated_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / MR #3 New Merge Request" - expected_message = u"Tomasz Kolek updated [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to Tomasz Kolek)\nfrom `tomek` to `master`\n\n~~~ quote\nupdated desc\n~~~" + expected_message = u"Tomasz Kolek updated [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)(assigned to Tomasz Kolek)\nfrom `tomek` to `master`\n\n~~~ quote\nupdated desc\n~~~" self.send_and_test_stream_message( 'merge_request_updated', expected_subject, @@ -210,7 +210,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_added_commit_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / MR #3 New Merge Request" - expected_message = u"Tomasz Kolek added commit(s) to [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)" + expected_message = u"Tomasz Kolek added commit(s) to [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)" self.send_and_test_stream_message( 'merge_request_added_commit', expected_subject, @@ -221,7 +221,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_merged_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / MR #3 New Merge Request" - expected_message = u"Tomasz Kolek merged [MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)" + expected_message = u"Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)" self.send_and_test_stream_message( 'merge_request_merged', diff --git a/zerver/views/webhooks/bitbucket2.py b/zerver/views/webhooks/bitbucket2.py index b997296ecf..94c2525451 100644 --- a/zerver/views/webhooks/bitbucket2.py +++ b/zerver/views/webhooks/bitbucket2.py @@ -211,6 +211,7 @@ def get_issue_action_body(payload, action): get_user_username(payload), action, issue['links']['html']['href'], + issue['id'], message, assignee ) @@ -222,6 +223,7 @@ def get_pull_request_action_body(payload, action): get_user_username(payload), action, get_pull_request_url(pull_request), + pull_request.get('id') ) def get_pull_request_created_or_updated_body(payload, action): @@ -235,6 +237,7 @@ def get_pull_request_created_or_updated_body(payload, action): get_user_username(payload), action, get_pull_request_url(pull_request), + pull_request.get('id'), target_branch=pull_request['source']['branch']['name'], base_branch=pull_request['destination']['branch']['name'], message=pull_request['description'], @@ -258,6 +261,7 @@ def get_pull_request_comment_action_body(payload, action): get_user_username(payload), action, payload['pullrequest']['links']['html']['href'], + payload['pullrequest']['id'], message=payload['comment']['content']['raw'] ) diff --git a/zerver/views/webhooks/github.py b/zerver/views/webhooks/github.py index 144b92b8c3..47297a43e3 100644 --- a/zerver/views/webhooks/github.py +++ b/zerver/views/webhooks/github.py @@ -38,6 +38,7 @@ def github_pull_request_content(payload): payload['sender']['login'], action, pull_request['html_url'], + pull_request['number'], pull_request['head']['ref'], pull_request['base']['ref'], pull_request['body'], @@ -47,6 +48,7 @@ def github_pull_request_content(payload): payload['sender']['login'], action, pull_request['html_url'], + pull_request['number'] ) def github_issues_content(payload): @@ -59,6 +61,7 @@ def github_issues_content(payload): payload['sender']['login'], action, issue['html_url'], + issue['number'], issue['body'], get_pull_request_or_issue_assignee(issue) ) @@ -66,6 +69,7 @@ def github_issues_content(payload): payload['sender']['login'], action, issue['html_url'], + issue['number'], ) def github_object_commented_content(payload, type): @@ -78,6 +82,7 @@ def github_object_commented_content(payload, type): comment['user']['login'], action, issue['html_url'], + issue['number'], message=comment['body'], type=type ) diff --git a/zerver/views/webhooks/gitlab.py b/zerver/views/webhooks/gitlab.py index d1994ebc57..5a77840a19 100644 --- a/zerver/views/webhooks/gitlab.py +++ b/zerver/views/webhooks/gitlab.py @@ -68,6 +68,7 @@ def get_issue_created_event_body(payload): get_issue_user_name(payload), 'created', get_object_url(payload), + payload.get('object_attributes').get('iid'), payload.get('object_attributes').get('description'), get_objects_assignee(payload) ) @@ -78,6 +79,7 @@ def get_issue_event_body(payload, action): get_issue_user_name(payload), action, get_object_url(payload), + payload.get('object_attributes').get('iid'), ) def get_merge_request_updated_event_body(payload): @@ -93,6 +95,7 @@ def get_merge_request_event_body(payload, action): get_issue_user_name(payload), action, pull_request.get('url'), + pull_request.get('iid'), type='MR', ) @@ -103,6 +106,7 @@ def get_merge_request_open_or_updated_body(payload, action): get_issue_user_name(payload), action, pull_request.get('url'), + pull_request.get('iid'), pull_request.get('source_branch'), pull_request.get('target_branch'), pull_request.get('description'), @@ -140,6 +144,7 @@ def get_commented_merge_request_event_body(payload): get_issue_user_name(payload), action, url, + payload.get('merge_request').get('iid'), message=comment['note'], type='MR' ) @@ -156,6 +161,7 @@ def get_commented_issue_event_body(payload): get_issue_user_name(payload), action, url, + payload.get('issue').get('iid'), message=comment['note'], type='Issue' ) @@ -172,6 +178,7 @@ def get_commented_snippet_event_body(payload): get_issue_user_name(payload), action, url, + payload.get('snippet').get('id'), message=comment['note'], type='Snippet' )