From ab8aae6d0ccabf676432e901b5c583279a5e57fa Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Fri, 19 Apr 2019 17:32:41 -0230 Subject: [PATCH] git_webhooks: Use proper punctuation for PR/issue messages. --- zerver/lib/webhooks/git.py | 43 +++++++++++++--- zerver/webhooks/bitbucket/tests.py | 4 +- zerver/webhooks/bitbucket/view.py | 2 +- zerver/webhooks/bitbucket2/tests.py | 59 +++++++++++----------- zerver/webhooks/bitbucket2/view.py | 13 ++++- zerver/webhooks/bitbucket3/tests.py | 32 ++++++------ zerver/webhooks/github/tests.py | 44 ++++++++--------- zerver/webhooks/github/view.py | 2 +- zerver/webhooks/gitlab/tests.py | 76 ++++++++++++++--------------- zerver/webhooks/gogs/tests.py | 12 ++--- 10 files changed, 160 insertions(+), 127 deletions(-) diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py index 5427641900..ae68835962 100644 --- a/zerver/lib/webhooks/git.py +++ b/zerver/lib/webhooks/git.py @@ -1,3 +1,4 @@ +import string from typing import Optional, Any, Dict, List, Tuple from collections import defaultdict TOPIC_WITH_BRANCH_TEMPLATE = '{repo} / {branch}' @@ -29,15 +30,15 @@ PUSH_COMMITS_MESSAGE_EXTENSION = "Commits by {}" PUSH_COMMITTERS_LIMIT_INFO = 3 FORCE_PUSH_COMMITS_MESSAGE_TEMPLATE = ("{user_name} [force pushed]({url}) " - "to branch {branch_name}. Head is now {head}") + "to branch {branch_name}. Head is now {head}.") CREATE_BRANCH_MESSAGE_TEMPLATE = "{user_name} created [{branch_name}]({url}) branch" CREATE_BRANCH_WITHOUT_URL_MESSAGE_TEMPLATE = "{user_name} created {branch_name} branch" -REMOVE_BRANCH_MESSAGE_TEMPLATE = "{user_name} deleted branch {branch_name}" +REMOVE_BRANCH_MESSAGE_TEMPLATE = "{user_name} deleted branch {branch_name}." PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE = "{user_name} {action} [{type}{id}]({url})" PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE_WITH_TITLE = "{user_name} {action} [{type}{id} {title}]({url})" PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE = "(assigned to {assignee})" -PULL_REQUEST_BRANCH_INFO_TEMPLATE = "\nfrom `{target}` to `{base}`" +PULL_REQUEST_BRANCH_INFO_TEMPLATE = "from `{target}` to `{base}`" SETUP_MESSAGE_TEMPLATE = "{integration} webhook has been successfully configured" SETUP_MESSAGE_USER_PART = " by {user_name}" @@ -157,16 +158,33 @@ def get_pull_request_event_message(user_name: str, action: str, url: str, number assignees_string = ", ".join(usernames[:-1]) + " and " + usernames[-1] - main_message += PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignees_string) + assignee_info = PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format( + assignee=assignees_string) + main_message = "{} {}".format(main_message, assignee_info) elif assignee: - main_message += PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignee) + assignee_info = PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format( + assignee=assignee) + main_message = "{} {}".format(main_message, assignee_info) if target_branch and base_branch: - main_message += PULL_REQUEST_BRANCH_INFO_TEMPLATE.format( + branch_info = PULL_REQUEST_BRANCH_INFO_TEMPLATE.format( target=target_branch, base=base_branch ) + main_message = "{} {}".format(main_message, branch_info) + + punctuation = ':' if message else '.' + if (assignees or assignee or (target_branch and base_branch) or (title is None)): + main_message = '{message}{punctuation}'.format( + message=main_message, punctuation=punctuation) + elif title is not None: + # Once we get here, we know that the message ends with a title + # which could already have punctuation at the end + if title[-1] not in string.punctuation: + main_message = '{message}{punctuation}'.format( + message=main_message, punctuation=punctuation) + if message: main_message += '\n' + CONTENT_MESSAGE_TEMPLATE.format(message=message) return main_message.rstrip() @@ -205,12 +223,18 @@ def get_push_tag_event_message(user_name: str, tag_part = TAG_WITH_URL_TEMPLATE.format(tag_name=tag_name, tag_url=tag_url) else: tag_part = TAG_WITHOUT_URL_TEMPLATE.format(tag_name=tag_name) - return PUSH_TAGS_MESSAGE_TEMPLATE.format( + + message = PUSH_TAGS_MESSAGE_TEMPLATE.format( user_name=user_name, action=action, tag=tag_part ) + if tag_name[-1] not in string.punctuation: + message = '{}.'.format(message) + + return message + def get_commits_comment_action_message(user_name: str, action: str, commit_url: str, @@ -222,10 +246,13 @@ def get_commits_comment_action_message(user_name: str, sha=get_short_sha(sha), url=commit_url ) - if message is not None: + punctuation = ':' if message else '.' + content = '{}{}'.format(content, punctuation) + if message: content += CONTENT_MESSAGE_TEMPLATE.format( message=message ) + return content def get_commits_content(commits_data: List[Dict[str, Any]], is_truncated: Optional[bool]=False) -> str: diff --git a/zerver/webhooks/bitbucket/tests.py b/zerver/webhooks/bitbucket/tests.py index 616a11ff43..709843d4db 100644 --- a/zerver/webhooks/bitbucket/tests.py +++ b/zerver/webhooks/bitbucket/tests.py @@ -57,14 +57,14 @@ class BitbucketHookTests(WebhookTestCase): def test_bitbucket_on_force_push_event(self) -> None: fixture_name = 'force_push' self.url = self.build_webhook_url(payload=self.get_body(fixture_name)) - expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)" + expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)." self.api_stream_message(self.TEST_USER_EMAIL, fixture_name, self.EXPECTED_TOPIC, expected_message) def test_bitbucket_on_force_push_event_without_user_info(self) -> None: fixture_name = 'force_push_without_user_info' self.url = self.build_webhook_url(payload=self.get_body(fixture_name)) - expected_message = u"Someone [force pushed](https://bitbucket.org/kolaszek/repository-name/)" + expected_message = u"Someone [force pushed](https://bitbucket.org/kolaszek/repository-name/)." self.api_stream_message(self.TEST_USER_EMAIL, fixture_name, self.EXPECTED_TOPIC, expected_message) diff --git a/zerver/webhooks/bitbucket/view.py b/zerver/webhooks/bitbucket/view.py index 932a274f54..e06e0cc906 100644 --- a/zerver/webhooks/bitbucket/view.py +++ b/zerver/webhooks/bitbucket/view.py @@ -35,7 +35,7 @@ def api_bitbucket_webhook(request: HttpRequest, user_profile: UserProfile, # Bitbucket doesn't give us enough information to really give # a useful message :/ subject = repository['name'] - content = (u"%s [force pushed](%s)" + content = (u"%s [force pushed](%s)." % (payload.get('user', 'Someone'), payload['canon_url'] + repository['absolute_url'])) else: diff --git a/zerver/webhooks/bitbucket2/tests.py b/zerver/webhooks/bitbucket2/tests.py index 44a8197531..e7e03a2b70 100644 --- a/zerver/webhooks/bitbucket2/tests.py +++ b/zerver/webhooks/bitbucket2/tests.py @@ -58,19 +58,20 @@ class Bitbucket2HookTests(WebhookTestCase): expected_message = u"kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5).\n\n{}[and more commit(s)]".format( (commit_info * 5), ) + self.send_and_test_stream_message('push_commits_above_limit', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) def test_bitbucket2_on_force_push_event(self) -> None: - expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12" + expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12." self.send_and_test_stream_message('force_push', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) def test_bitbucket2_on_force_push_event_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches='master,development') - expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12" + expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12." self.send_and_test_stream_message('force_push', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) def test_bitbucket2_on_remove_branch_event(self) -> None: - expected_message = u"kolaszek deleted branch master" + expected_message = u"kolaszek deleted branch master." self.send_and_test_stream_message('remove_branch', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message) def test_bitbucket2_on_fork_event(self) -> None: @@ -78,7 +79,7 @@ class Bitbucket2HookTests(WebhookTestCase): self.send_and_test_stream_message('fork', self.EXPECTED_TOPIC, expected_message) def test_bitbucket2_on_commit_comment_created_event(self) -> None: - expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [32c4ea1](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74)\n~~~ quote\nNice fix!\n~~~" + expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [32c4ea1](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74):\n~~~ quote\nNice fix!\n~~~" self.send_and_test_stream_message('commit_comment_created', self.EXPECTED_TOPIC, expected_message) def test_bitbucket2_on_commit_status_changed_event(self) -> None: @@ -86,31 +87,31 @@ class Bitbucket2HookTests(WebhookTestCase): self.send_and_test_stream_message('commit_status_changed', self.EXPECTED_TOPIC, expected_message) def test_bitbucket2_on_issue_created_event(self) -> None: - 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~~~" + 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('issue_created', self.EXPECTED_TOPIC_ISSUE_EVENTS, expected_message) def test_bitbucket2_on_issue_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") expected_topic = u"notifications" - expected_message = u"kolaszek created [Issue #1 Bug](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 Bug](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('issue_created', expected_topic, expected_message) def test_bitbucket2_on_issue_updated_event(self) -> None: - expected_message = u"kolaszek updated [Issue #1](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('issue_updated', self.EXPECTED_TOPIC_ISSUE_EVENTS, expected_message) def test_bitbucket2_on_issue_commented_event(self) -> None: - 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)" + 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('issue_commented', self.EXPECTED_TOPIC_ISSUE_EVENTS, expected_message) def test_bitbucket2_on_issue_commented_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") expected_topic = u"notifications" - expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/issues/2#comment-28973596) on [Issue #1 Bug](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 Bug](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)." self.send_and_test_stream_message('issue_commented', expected_topic, expected_message) def test_bitbucket2_on_pull_request_created_event(self) -> None: - 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~~~" + expected_message = u"kolaszek created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to tkolek) from `new-branch` to `master`:\n\n~~~ quote\ndescription\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:created' } @@ -119,21 +120,21 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") expected_topic = u"notifications" - expected_message = u"kolaszek created [PR #1 new commit](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 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to tkolek) from `new-branch` to `master`:\n\n~~~ quote\ndescription\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:created' } self.send_and_test_stream_message('pull_request_created_or_updated', expected_topic, expected_message, **kwargs) def test_bitbucket2_on_pull_request_updated_event(self) -> None: - 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~~~" + expected_message = u"kolaszek updated [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to tkolek) from `new-branch` to `master`:\n\n~~~ quote\ndescription\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:updated' } self.send_and_test_stream_message('pull_request_created_or_updated', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, **kwargs) def test_bitbucket2_on_pull_request_approved_event(self) -> None: - expected_message = u"kolaszek approved [PR #1](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' } @@ -142,35 +143,35 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_approved_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") expected_topic = u"notifications" - expected_message = u"kolaszek approved [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)" + expected_message = u"kolaszek approved [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)." kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:approved' } self.send_and_test_stream_message('pull_request_approved_or_unapproved', expected_topic, expected_message, **kwargs) def test_bitbucket2_on_pull_request_unapproved_event(self) -> None: - expected_message = u"kolaszek unapproved [PR #1](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' } self.send_and_test_stream_message('pull_request_approved_or_unapproved', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, **kwargs) def test_bitbucket2_on_pull_request_declined_event(self) -> None: - expected_message = u"kolaszek rejected [PR #1](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' } self.send_and_test_stream_message('pull_request_fulfilled_or_rejected', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, **kwargs) def test_bitbucket2_on_pull_request_fulfilled_event(self) -> None: - expected_message = u"kolaszek merged [PR #1](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:fulfilled' } self.send_and_test_stream_message('pull_request_fulfilled_or_rejected', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, **kwargs) def test_bitbucket2_on_pull_request_comment_created_event(self) -> None: - 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~~~" + 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' } @@ -179,14 +180,14 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_comment_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") expected_topic = u"notifications" - expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](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 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:comment_created' } self.send_and_test_stream_message('pull_request_comment_action', expected_topic, expected_message, **kwargs) def test_bitbucket2_on_pull_request_comment_updated_event(self) -> None: - expected_message = u"kolaszek updated a [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~~~" + expected_message = u"kolaszek updated a [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' } @@ -195,42 +196,42 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_comment_updated_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") expected_topic = u"notifications" - expected_message = u"kolaszek updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3)\n\n~~~ quote\nComment1\n~~~" + expected_message = u"kolaszek updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~" kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:comment_updated' } self.send_and_test_stream_message('pull_request_comment_action', expected_topic, expected_message, **kwargs) def test_bitbucket2_on_pull_request_comment_deleted_event(self) -> None: - expected_message = u"kolaszek deleted a [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~~~" + expected_message = u"kolaszek deleted a [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' } self.send_and_test_stream_message('pull_request_comment_action', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, **kwargs) def test_bitbucket2_on_repo_updated_event(self) -> None: - expected_message = u"eeshangarg changed the website of the **new-name** repo to **http://zulipchat.com**\neeshangarg changed the name of the **new-name** repo from **test-repo** to **new-name**\neeshangarg changed the language of the **new-name** repo to **python**\neeshangarg changed the full name of the **new-name** repo from **webhooktest/test-repo** to **webhooktest/new-name**\neeshangarg changed the description of the **new-name** repo to **Random description.**" + expected_message = u"eeshangarg changed the website of the **new-name** repo to **http://zulipchat.com**.\neeshangarg changed the name of the **new-name** repo from **test-repo** to **new-name**.\neeshangarg changed the language of the **new-name** repo to **python**.\neeshangarg changed the full name of the **new-name** repo from **webhooktest/test-repo** to **webhooktest/new-name**.\neeshangarg changed the description of the **new-name** repo to **Random description.**" expected_topic = u"new-name" kwargs = {"HTTP_X_EVENT_KEY": 'repo:updated'} self.send_and_test_stream_message('repo_updated', expected_topic, expected_message, **kwargs) def test_bitbucket2_on_push_one_tag_event(self) -> None: - expected_message = u"kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)" + expected_message = u"kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)." kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:push' } self.send_and_test_stream_message('push_one_tag', self.EXPECTED_TOPIC, expected_message, **kwargs) def test_bitbucket2_on_push_remove_tag_event(self) -> None: - expected_message = u"kolaszek removed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)" + expected_message = u"kolaszek removed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)." kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:push' } self.send_and_test_stream_message('push_remove_tag', self.EXPECTED_TOPIC, expected_message, **kwargs) def test_bitbucket2_on_push_more_than_one_tag_event(self) -> None: - expected_message = u"kolaszek pushed tag [{name}](https://bitbucket.org/kolaszek/repository-name/commits/tag/{name})" + expected_message = u"kolaszek pushed tag [{name}](https://bitbucket.org/kolaszek/repository-name/commits/tag/{name})." kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:push' } @@ -251,7 +252,7 @@ class Bitbucket2HookTests(WebhookTestCase): self.do_test_message(msg, 'kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master.\n\n* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))') self.do_test_topic(msg, self.EXPECTED_TOPIC_BRANCH_EVENTS) msg = self.get_last_message() - self.do_test_message(msg, 'kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)') + self.do_test_message(msg, 'kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a).') self.do_test_topic(msg, self.EXPECTED_TOPIC) def test_bitbucket2_on_more_than_one_push_event_filtered_by_branches(self) -> None: @@ -264,7 +265,7 @@ class Bitbucket2HookTests(WebhookTestCase): self.do_test_message(msg, 'kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master.\n\n* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))') self.do_test_topic(msg, self.EXPECTED_TOPIC_BRANCH_EVENTS) msg = self.get_last_message() - self.do_test_message(msg, 'kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)') + self.do_test_message(msg, 'kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a).') self.do_test_topic(msg, self.EXPECTED_TOPIC) def test_bitbucket2_on_more_than_one_push_event_filtered_by_branches_ignore(self) -> None: @@ -272,7 +273,7 @@ class Bitbucket2HookTests(WebhookTestCase): kwargs = { "HTTP_X_EVENT_KEY": 'pullrequest:push' } - expected_message = u"kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)" + expected_message = u"kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)." self.send_and_test_stream_message('more_than_one_push_event', self.EXPECTED_TOPIC, expected_message, **kwargs) diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.py index 16fbd2cde2..c342f9d9c5 100644 --- a/zerver/webhooks/bitbucket2/view.py +++ b/zerver/webhooks/bitbucket2/view.py @@ -1,6 +1,7 @@ # Webhooks for external integrations. import re from functools import partial +import string from typing import Any, Dict, List, Optional from inspect import signature @@ -26,8 +27,8 @@ BITBUCKET_FORK_BODY = USER_PART + ' forked the repository into [{fork_name}]({fo BITBUCKET_COMMIT_STATUS_CHANGED_BODY = ('[System {key}]({system_url}) changed status of' ' {commit_info} to {status}.') BITBUCKET_REPO_UPDATED_CHANGED = ('{actor} changed the {change} of the **{repo_name}**' - ' repo from **{old}** to **{new}**\n') -BITBUCKET_REPO_UPDATED_ADDED = '{actor} changed the {change} of the **{repo_name}** repo to **{new}**\n' + ' repo from **{old}** to **{new}**') +BITBUCKET_REPO_UPDATED_ADDED = '{actor} changed the {change} of the **{repo_name}** repo to **{new}**' PULL_REQUEST_SUPPORTED_ACTIONS = [ 'approved', @@ -342,6 +343,12 @@ def get_push_tag_body(payload: Dict[str, Any], change: Dict[str, Any]) -> str: action=action ) +def append_punctuation(title: str, message: str) -> str: + if title[-1] not in string.punctuation: + message = "{}.".format(message) + + return message + def get_repo_updated_body(payload: Dict[str, Any]) -> str: changes = ['website', 'name', 'links', 'language', 'full_name', 'description'] body = "" @@ -358,11 +365,13 @@ def get_repo_updated_body(payload: Dict[str, Any]) -> str: actor=actor, change=change, repo_name=repo_name, old=old, new=new ) + message = append_punctuation(new, message) + '\n' body += message elif new and not old: message = BITBUCKET_REPO_UPDATED_ADDED.format( actor=actor, change=change, repo_name=repo_name, new=new ) + message = append_punctuation(new, message) + '\n' body += message return body diff --git a/zerver/webhooks/bitbucket3/tests.py b/zerver/webhooks/bitbucket3/tests.py index 8f7a55f632..6c12782a15 100644 --- a/zerver/webhooks/bitbucket3/tests.py +++ b/zerver/webhooks/bitbucket3/tests.py @@ -10,19 +10,19 @@ class Bitbucket3HookTests(WebhookTestCase): # Core Repo Events: def test_commit_comment_added(self) -> None: - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) commented on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907)\n~~~ quote\nJust an arbitrary comment on a commit.\n~~~""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) commented on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907):\n~~~ quote\nJust an arbitrary comment on a commit.\n~~~""" self.send_and_test_stream_message("commit_comment_added", self.EXPECTED_TOPIC, expected_message) def test_commit_comment_edited(self) -> None: - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) edited their comment on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907)\n~~~ quote\nJust an arbitrary comment on a commit. Nothing to see here...\n~~~""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) edited their comment on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907):\n~~~ quote\nJust an arbitrary comment on a commit. Nothing to see here...\n~~~""" self.send_and_test_stream_message("commit_comment_edited", self.EXPECTED_TOPIC, expected_message) def test_commit_comment_deleted(self) -> None: - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted their comment on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907)\n~~~ quote\n~~Just an arbitrary comment on a commit. Nothing to see here...~~\n~~~""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted their comment on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907):\n~~~ quote\n~~Just an arbitrary comment on a commit. Nothing to see here...~~\n~~~""" self.send_and_test_stream_message("commit_comment_deleted", self.EXPECTED_TOPIC, expected_message) @@ -45,20 +45,20 @@ class Bitbucket3HookTests(WebhookTestCase): expected_message) def test_push_add_tag(self) -> None: - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) pushed tag newtag""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) pushed tag newtag.""" self.send_and_test_stream_message("repo_push_add_tag", self.EXPECTED_TOPIC, expected_message) def test_push_delete_branch(self) -> None: - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted branch branch2""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted branch branch2.""" expected_topic = self.EXPECTED_TOPIC_BRANCH_EVENTS.format(branch="branch2") self.send_and_test_stream_message("repo_push_delete_branch", expected_topic, expected_message) def test_push_delete_tag(self) -> None: - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) removed tag test-tag""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) removed tag test-tag.""" self.send_and_test_stream_message("repo_push_delete_tag", self.EXPECTED_TOPIC, expected_message) @@ -101,14 +101,14 @@ class Bitbucket3HookTests(WebhookTestCase): # Core PR Events: def test_pr_opened_without_reviewers(self) -> None: expected_topic = "sandbox / PR #1 Branch1" - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1)\nfrom `branch1` to `master`\n\n~~~ quote\n* Add file2.txt\r\n* Add file3.txt\n~~~""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) from `branch1` to `master`:\n\n~~~ quote\n* Add file2.txt\r\n* Add file3.txt\n~~~""" self.send_and_test_stream_message("pull_request_opened_without_reviewers", expected_topic, expected_message) def test_pr_opened_without_description(self) -> None: expected_topic = "sandbox / PR #2 Add notes feature." - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #2](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/2)\nfrom `master` to `master`""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #2](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/2) from `master` to `master`.""" self.send_and_test_stream_message("pull_request_opened_without_description", expected_topic, expected_message) @@ -153,7 +153,7 @@ class Bitbucket3HookTests(WebhookTestCase): def test_pr_deleted(self) -> None: expected_topic = "sandbox / PR #2 Add notes feature." - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted [PR #2](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/2)""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted [PR #2](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/2).""" self.send_and_test_stream_message("pull_request_deleted", expected_topic, expected_message) @@ -168,14 +168,14 @@ class Bitbucket3HookTests(WebhookTestCase): def test_pr_declined(self) -> None: expected_topic = "sandbox / PR #7 Crazy Idea" - expected_message = """[zura](http://139.59.64.214:7990/users/zura) declined [PR #7](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/7)""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) declined [PR #7](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/7).""" self.send_and_test_stream_message("pull_request_declined", expected_topic, expected_message) def test_pr_merged(self) -> None: expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." - expected_message = """[zura](http://139.59.64.214:7990/users/zura) merged [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) merged [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6).""" self.send_and_test_stream_message("pull_request_merged", expected_topic, expected_message) @@ -183,14 +183,14 @@ class Bitbucket3HookTests(WebhookTestCase): # PR Reviewer Events: def test_pr_approved(self) -> None: expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." - expected_message = """[zura](http://139.59.64.214:7990/users/zura) approved [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) approved [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6).""" self.send_and_test_stream_message("pull_request_approved", expected_topic, expected_message) def test_pr_unapproved(self) -> None: expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." - expected_message = """[zura](http://139.59.64.214:7990/users/zura) unapproved [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) unapproved [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6).""" self.send_and_test_stream_message("pull_request_unapproved", expected_topic, expected_message) @@ -250,21 +250,21 @@ class Bitbucket3HookTests(WebhookTestCase): # PR Comment Events: def test_pull_request_comment_added(self) -> None: - expected_message = """[zura](http://139.59.64.214:7990/users/zura) commented on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)\n\n~~~ quote\nThis seems like a pretty good idea.\n~~~""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) commented on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6):\n\n~~~ quote\nThis seems like a pretty good idea.\n~~~""" expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." self.send_and_test_stream_message("pull_request_comment_added", expected_topic, expected_message) def test_pull_request_comment_edited(self) -> None: - expected_message = """[zura](http://139.59.64.214:7990/users/zura) edited their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)\n\n~~~ quote\nThis seems like a pretty good idea. @shimura what do you think?\n~~~""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) edited their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6):\n\n~~~ quote\nThis seems like a pretty good idea. @shimura what do you think?\n~~~""" expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." self.send_and_test_stream_message("pull_request_comment_edited", expected_topic, expected_message) def test_pull_request_comment_deleted(self) -> None: - expected_message = """[zura](http://139.59.64.214:7990/users/zura) deleted their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)\n\n~~~ quote\n~~This seems like a pretty good idea. @shimura what do you think?~~\n~~~""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) deleted their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6):\n\n~~~ quote\n~~This seems like a pretty good idea. @shimura what do you think?~~\n~~~""" expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." self.send_and_test_stream_message("pull_request_comment_deleted", expected_topic, diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py index 9be9eb5c89..1bd7525e8d 100644 --- a/zerver/webhooks/github/tests.py +++ b/zerver/webhooks/github/tests.py @@ -86,7 +86,7 @@ class GithubWebhookTest(WebhookTestCase): self.send_and_test_stream_message('push_50_commits', self.EXPECTED_TOPIC_BRANCH_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='push') def test_commit_comment_msg(self) -> None: - expected_message = u"baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b#commitcomment-11056394) on [9049f12](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b)\n~~~ quote\nThis is a really good change! :+1:\n~~~" + expected_message = u"baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b#commitcomment-11056394) on [9049f12](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b):\n~~~ quote\nThis is a really good change! :+1:\n~~~" self.send_and_test_stream_message('commit_comment', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='commit_comment') def test_create_msg(self) -> None: @@ -110,12 +110,12 @@ class GithubWebhookTest(WebhookTestCase): self.send_and_test_stream_message('fork', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='fork') def test_issue_comment_msg(self) -> None: - expected_message = u"baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [Issue #2](https://github.com/baxterthehacker/public-repo/issues/2)\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~" + expected_message = u"baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [Issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~" self.send_and_test_stream_message('issue_comment', self.EXPECTED_TOPIC_ISSUE_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='issue_comment') def test_issue_comment_deleted_msg(self) -> None: expected_topic = u"Scheduler / Issue #5 This is a new issue" - expected_message = u"eeshangarg deleted a [comment](https://github.com/eeshangarg/Scheduler/issues/5#issuecomment-425164194) on [Issue #5](https://github.com/eeshangarg/Scheduler/issues/5)\n\n~~~ quote\nThis is a comment on this new issue.\n~~~" + expected_message = u"eeshangarg deleted a [comment](https://github.com/eeshangarg/Scheduler/issues/5#issuecomment-425164194) on [Issue #5](https://github.com/eeshangarg/Scheduler/issues/5):\n\n~~~ quote\nThis is a comment on this new issue.\n~~~" self.send_and_test_stream_message( 'issue_comment_deleted', expected_topic, @@ -126,17 +126,17 @@ class GithubWebhookTest(WebhookTestCase): def test_issue_comment_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [Issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2)\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~" + expected_message = u"baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [Issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~" self.send_and_test_stream_message('issue_comment', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='issue_comment') def test_issue_msg(self) -> None: - expected_message = u"baxterthehacker opened [Issue #2](https://github.com/baxterthehacker/public-repo/issues/2)\n\n~~~ quote\nIt looks like you accidently spelled 'commit' with two 't's.\n~~~" + expected_message = u"baxterthehacker opened [Issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nIt looks like you accidently spelled 'commit' with two 't's.\n~~~" self.send_and_test_stream_message('issue', self.EXPECTED_TOPIC_ISSUE_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='issues') def test_issue_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"baxterthehacker opened [Issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2)\n\n~~~ quote\nIt looks like you accidently spelled 'commit' with two 't's.\n~~~" + expected_message = u"baxterthehacker opened [Issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nIt looks like you accidently spelled 'commit' with two 't's.\n~~~" self.send_and_test_stream_message('issue', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='issues') def test_membership_msg(self) -> None: @@ -158,12 +158,12 @@ class GithubWebhookTest(WebhookTestCase): self.send_and_test_stream_message('member', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='member') def test_pull_request_opened_msg(self) -> None: - expected_message = u"baxterthehacker opened [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)\nfrom `changes` to `master`\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~" + expected_message = u"baxterthehacker opened [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~" self.send_and_test_stream_message('opened_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_opened_with_preassigned_assignee_msg(self) -> None: expected_topic = u"Scheduler / PR #4 Improve README" - expected_message = u"eeshangarg opened [PR #4](https://github.com/eeshangarg/Scheduler/pull/4)(assigned to eeshangarg)\nfrom `improve-readme-2` to `master`" + expected_message = u"eeshangarg opened [PR #4](https://github.com/eeshangarg/Scheduler/pull/4) (assigned to eeshangarg) from `improve-readme-2` to `master`." self.send_and_test_stream_message('opened_pull_request_with_preassigned_assignee', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='pull_request') @@ -171,25 +171,25 @@ class GithubWebhookTest(WebhookTestCase): def test_pull_request_opened_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"baxterthehacker opened [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1)\nfrom `changes` to `master`\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~" + expected_message = u"baxterthehacker opened [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~" self.send_and_test_stream_message('opened_pull_request', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_synchronized_msg(self) -> None: - expected_message = u"baxterthehacker updated [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)\nfrom `changes` to `master`" + expected_message = u"baxterthehacker updated [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`." self.send_and_test_stream_message('synchronized_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_closed_msg(self) -> None: - expected_message = u"baxterthehacker closed without merge [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)" + expected_message = u"baxterthehacker closed without merge [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)." self.send_and_test_stream_message('closed_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_closed_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"baxterthehacker closed without merge [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1)" + expected_message = u"baxterthehacker closed without merge [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1)." self.send_and_test_stream_message('closed_pull_request', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_merged_msg(self) -> None: - expected_message = u"baxterthehacker merged [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)" + expected_message = u"baxterthehacker merged [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)." self.send_and_test_stream_message('merged_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_public_msg(self) -> None: @@ -234,48 +234,48 @@ class GithubWebhookTest(WebhookTestCase): ) def test_pull_request_review_msg(self) -> None: - expected_message = u"baxterthehacker submitted [PR Review](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884)" + expected_message = u"baxterthehacker submitted [PR Review](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884)." self.send_and_test_stream_message('pull_request_review', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request_review') def test_pull_request_review_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"baxterthehacker submitted [PR Review for #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884)" + expected_message = u"baxterthehacker submitted [PR Review for #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884)." self.send_and_test_stream_message('pull_request_review', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='pull_request_review') def test_pull_request_review_comment_msg(self) -> None: - expected_message = u"baxterthehacker created [PR Review Comment](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692)\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~" + expected_message = u"baxterthehacker created [PR Review Comment](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~" self.send_and_test_stream_message('pull_request_review_comment', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request_review_comment') def test_pull_request_review_comment_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"baxterthehacker created [PR Review Comment on #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692)\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~" + expected_message = u"baxterthehacker created [PR Review Comment on #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~" self.send_and_test_stream_message('pull_request_review_comment', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='pull_request_review_comment') def test_push_tag_msg(self) -> None: - expected_message = u"baxterthehacker pushed tag abc" + expected_message = u"baxterthehacker pushed tag abc." self.send_and_test_stream_message('push_tag', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='push') def test_pull_request_edited_msg(self) -> None: - expected_message = u"baxterthehacker edited [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)\nfrom `changes` to `master`" + expected_message = u"baxterthehacker edited [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `changes` to `master`." self.send_and_test_stream_message('edited_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_assigned_msg(self) -> None: - expected_message = u"baxterthehacker assigned [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) to baxterthehacker" + expected_message = u"baxterthehacker assigned [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) to baxterthehacker." self.send_and_test_stream_message('assigned_pull_request', self.EXPECTED_TOPIC_PR_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_assigned_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"baxterthehacker assigned [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) to baxterthehacker" + expected_message = u"baxterthehacker assigned [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) to baxterthehacker." self.send_and_test_stream_message('assigned_pull_request', expected_topic, expected_message, HTTP_X_GITHUB_EVENT='pull_request') def test_pull_request_unassigned_msg(self) -> None: - expected_message = u"eeshangarg unassigned [PR #1](https://github.com/zulip-test-org/helloworld/pull/1)" + expected_message = u"eeshangarg unassigned [PR #1](https://github.com/zulip-test-org/helloworld/pull/1)." self.send_and_test_stream_message( 'unassigned_pull_request', 'helloworld / PR #1 Mention that Zulip rocks!', diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index 07087216ba..6df4454106 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -57,7 +57,7 @@ def get_assigned_or_unassigned_pull_request_body(payload: Dict[str, Any], title=pull_request['title'] if include_title else None ) if assignee is not None: - return "{} to {}".format(base_message, assignee) + return "{} to {}.".format(base_message[:-1], assignee) return base_message def get_closed_pull_request_body(payload: Dict[str, Any], diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py index e065025c80..7e0d637fe4 100644 --- a/zerver/webhooks/gitlab/tests.py +++ b/zerver/webhooks/gitlab/tests.py @@ -63,13 +63,13 @@ class GitlabHookTests(WebhookTestCase): def test_remove_branch_event_message(self) -> None: expected_topic = u"my-awesome-project / tomek" - expected_message = u"Tomasz Kolek deleted branch tomek" + expected_message = u"Tomasz Kolek deleted branch tomek." self.send_and_test_stream_message('remove_branch', expected_topic, expected_message, HTTP_X_GITLAB_EVENT="Push Hook") def test_add_tag_event_message(self) -> None: expected_topic = u"my-awesome-project" - expected_message = u"Tomasz Kolek pushed tag xyz" + expected_message = u"Tomasz Kolek pushed tag xyz." self.send_and_test_stream_message( 'add_tag', @@ -80,7 +80,7 @@ class GitlabHookTests(WebhookTestCase): def test_remove_tag_event_message(self) -> None: expected_topic = u"my-awesome-project" - expected_message = u"Tomasz Kolek removed tag xyz" + expected_message = u"Tomasz Kolek removed tag xyz." self.send_and_test_stream_message( 'remove_tag', @@ -91,7 +91,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_without_assignee_event_message(self) -> None: expected_topic = u"my-awesome-project / Issue #1 Issue title" - expected_message = u"Tomasz Kolek created [Issue #1](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', @@ -102,7 +102,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_confidential_issue_without_assignee_event_message(self) -> None: expected_subject = u"testing / Issue #1 Testing" - expected_message = u"Joe Bloggs created [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)\n\n~~~ quote\nTesting\n~~~" + expected_message = u"Joe Bloggs created [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1):\n\n~~~ quote\nTesting\n~~~" self.send_and_test_stream_message( 'confidential_issue_created_without_assignee', @@ -114,7 +114,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"Tomasz Kolek created [Issue #1 Issue title](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)\n\n~~~ quote\nIssue description\n~~~" + expected_message = u"Tomasz Kolek created [Issue #1 Issue title](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', @@ -125,7 +125,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_assignee_event_message(self) -> None: expected_topic = u"my-awesome-project / Issue #1 Issue title" - 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~~~" + 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', @@ -136,7 +136,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_two_assignees_event_message(self) -> None: expected_subject = u"Zulip GitLab Test / Issue #2 Zulip Test Issue 2" - expected_message = u"Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2)(assigned to adambirds and eeshangarg)\n\n~~~ quote\nZulip Test Issue 2\n~~~" + expected_message = u"Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2) (assigned to adambirds and eeshangarg):\n\n~~~ quote\nZulip Test Issue 2\n~~~" self.send_and_test_stream_message( 'issue_created_with_two_assignees', @@ -147,7 +147,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_three_assignees_event_message(self) -> None: expected_subject = u"Zulip GitLab Test / Issue #2 Zulip Test Issue 2" - expected_message = u"Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2)(assigned to adambirds, eeshangarg and timabbott)\n\n~~~ quote\nZulip Test Issue 2\n~~~" + expected_message = u"Adam Birds created [Issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2) (assigned to adambirds, eeshangarg and timabbott):\n\n~~~ quote\nZulip Test Issue 2\n~~~" self.send_and_test_stream_message( 'issue_created_with_three_assignees', @@ -158,7 +158,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_confidential_issue_with_assignee_event_message(self) -> None: expected_subject = u"testing / Issue #2 Testing" - expected_message = u"Joe Bloggs created [Issue #2](https://gitlab.example.co.uk/joe.bloggs/testing/issues/2)(assigned to joe.bloggs)\n\n~~~ quote\nTesting\n~~~" + expected_message = u"Joe Bloggs created [Issue #2](https://gitlab.example.co.uk/joe.bloggs/testing/issues/2) (assigned to joe.bloggs):\n\n~~~ quote\nTesting\n~~~" self.send_and_test_stream_message( 'confidential_issue_created_with_assignee', @@ -169,7 +169,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_hidden_comment_in_description(self) -> None: expected_topic = u"public-repo / Issue #3 New Issue with hidden comment" - expected_message = u"Eeshan Garg created [Issue #3](https://gitlab.com/eeshangarg/public-repo/issues/3)\n\n~~~ quote\nThis description actually has a hidden comment in it!\n~~~" + expected_message = u"Eeshan Garg created [Issue #3](https://gitlab.com/eeshangarg/public-repo/issues/3):\n\n~~~ quote\nThis description actually has a hidden comment in it!\n~~~" self.send_and_test_stream_message( 'issue_created_with_hidden_comment_in_description', @@ -180,7 +180,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_confidential_issue_with_hidden_comment_in_description(self) -> None: expected_subject = u"testing / Issue #1 Testing" - expected_message = u"Joe Bloggs created [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)\n\n~~~ quote\nThis description actually has a hidden comment in it!\n~~~" + expected_message = u"Joe Bloggs created [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1):\n\n~~~ quote\nThis description actually has a hidden comment in it!\n~~~" self.send_and_test_stream_message( 'confidential_issue_created_with_hidden_comment_in_description', @@ -191,7 +191,7 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_null_description(self) -> None: expected_topic = u"my-awesome-project / Issue #7 Issue without description" - expected_message = u"Eeshan Garg created [Issue #7](https://gitlab.com/eeshangarg/my-awesome-project/issues/7)" + expected_message = u"Eeshan Garg created [Issue #7](https://gitlab.com/eeshangarg/my-awesome-project/issues/7)." self.send_and_test_stream_message( 'issue_opened_with_null_description', expected_topic, @@ -201,7 +201,7 @@ class GitlabHookTests(WebhookTestCase): def test_update_issue_event_message(self) -> None: expected_topic = u"my-awesome-project / Issue #1 Issue title_new" - expected_message = u"Tomasz Kolek updated [Issue #1](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', @@ -212,7 +212,7 @@ class GitlabHookTests(WebhookTestCase): def test_update_confidential_issue_event_message(self) -> None: expected_subject = u"testing / Issue #1 Testing" - expected_message = u"Joe Bloggs updated [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)" + expected_message = u"Joe Bloggs updated [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)." self.send_and_test_stream_message( 'confidential_issue_updated', @@ -224,7 +224,7 @@ class GitlabHookTests(WebhookTestCase): def test_update_issue_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"Tomasz Kolek updated [Issue #1 Issue title_new](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)" + expected_message = u"Tomasz Kolek updated [Issue #1 Issue title_new](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)." self.send_and_test_stream_message( 'issue_updated', @@ -235,7 +235,7 @@ class GitlabHookTests(WebhookTestCase): def test_close_issue_event_message(self) -> None: expected_topic = u"my-awesome-project / Issue #1 Issue title_new" - expected_message = u"Tomasz Kolek closed [Issue #1](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', @@ -246,7 +246,7 @@ class GitlabHookTests(WebhookTestCase): def test_close_confidential_issue_event_message(self) -> None: expected_subject = u"testing / Issue #1 Testing Test" - expected_message = u"Joe Bloggs closed [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)" + expected_message = u"Joe Bloggs closed [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)." self.send_and_test_stream_message( 'confidential_issue_closed', @@ -257,7 +257,7 @@ class GitlabHookTests(WebhookTestCase): def test_reopen_issue_event_message(self) -> None: expected_topic = u"my-awesome-project / Issue #1 Issue title_new" - expected_message = u"Tomasz Kolek reopened [Issue #1](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', @@ -268,7 +268,7 @@ class GitlabHookTests(WebhookTestCase): def test_reopen_confidential_issue_event_message(self) -> None: expected_subject = u"testing / Issue #1 Testing Test" - expected_message = u"Joe Bloggs reopened [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)" + expected_message = u"Joe Bloggs reopened [Issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)." self.send_and_test_stream_message( 'confidential_issue_reopened', @@ -279,7 +279,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_commit_event_message(self) -> None: expected_topic = u"my-awesome-project" - expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7#note_14169211) on [66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7)\n~~~ quote\nnice commit\n~~~" + expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7#note_14169211) on [66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7):\n~~~ quote\nnice commit\n~~~" self.send_and_test_stream_message( 'commit_note', @@ -290,7 +290,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_merge_request_event_message(self) -> None: expected_topic = 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 #1](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', @@ -302,7 +302,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_merge_request_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/1#note_14171860) on [MR #1 Tomek](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 Tomek](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', @@ -313,7 +313,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_issue_event_message(self) -> None: expected_topic = 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 #2](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', @@ -324,7 +324,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_confidential_issue_event_message(self) -> None: expected_subject = u"Test / Issue #3 Test" - expected_message = u"Joe Bloggs [commented](https://gitlab.com/joebloggs/test/issues/3#note_101638770) on [Issue #3](https://gitlab.com/joebloggs/test/issues/3)\n\n~~~ quote\nTest\n~~~" + expected_message = u"Joe Bloggs [commented](https://gitlab.com/joebloggs/test/issues/3#note_101638770) on [Issue #3](https://gitlab.com/joebloggs/test/issues/3):\n\n~~~ quote\nTest\n~~~" self.send_and_test_stream_message( 'confidential_issue_note', @@ -336,7 +336,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_issue_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2#note_14172057) on [Issue #2 abc](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 abc](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/2):\n\n~~~ quote\nNice issue\n~~~" self.send_and_test_stream_message( 'issue_note', @@ -347,7 +347,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_snippet_event_message(self) -> None: expected_topic = 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 #2](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', @@ -359,7 +359,7 @@ class GitlabHookTests(WebhookTestCase): def test_note_snippet_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [Snippet #2 test](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 test](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2):\n\n~~~ quote\nNice snippet\n~~~" self.send_and_test_stream_message( 'snippet_note', @@ -370,7 +370,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_created_without_assignee_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #2 NEW MR" - 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~~~" + expected_message = u"Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n~~~ quote\ndescription of merge request\n~~~" self.send_and_test_stream_message( 'merge_request_created_without_assignee', @@ -382,7 +382,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"Tomasz Kolek created [MR #2 NEW 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 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n~~~ quote\ndescription of merge request\n~~~" self.send_and_test_stream_message( 'merge_request_created_without_assignee', @@ -393,7 +393,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_created_with_assignee_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #3 New Merge Request" - 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~~~" + expected_message = u"Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) (assigned to Tomasz Kolek) from `tomek` to `master`:\n\n~~~ quote\ndescription of merge request\n~~~" self.send_and_test_stream_message( 'merge_request_created_with_assignee', expected_topic, @@ -403,7 +403,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_closed_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #2 NEW MR" - expected_message = u"Tomasz Kolek closed [MR #2](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', @@ -415,7 +415,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_closed_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)" + expected_message = u"Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)." self.send_and_test_stream_message( 'merge_request_closed', @@ -426,7 +426,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_reopened_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #1 Update the README with author ..." - expected_message = u"Eeshan Garg reopened [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)" + expected_message = u"Eeshan Garg reopened [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)." self.send_and_test_stream_message( 'merge_request_reopened', @@ -437,7 +437,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_approved_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #1 Update the README with author ..." - expected_message = u"Eeshan Garg approved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)" + expected_message = u"Eeshan Garg approved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)." self.send_and_test_stream_message( 'merge_request_approved', @@ -448,7 +448,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_updated_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #3 New Merge Request" - 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~~~" + expected_message = u"Tomasz Kolek updated [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) (assigned to Tomasz Kolek) from `tomek` to `master`:\n\n~~~ quote\nupdated desc\n~~~" self.send_and_test_stream_message( 'merge_request_updated', expected_topic, @@ -458,7 +458,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_added_commit_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #3 New Merge Request" - expected_message = u"Tomasz Kolek added commit(s) to [MR #3](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_topic, @@ -468,7 +468,7 @@ class GitlabHookTests(WebhookTestCase): def test_merge_request_merged_event_message(self) -> None: expected_topic = u"my-awesome-project / MR #3 New Merge Request" - expected_message = u"Tomasz Kolek merged [MR #3](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/webhooks/gogs/tests.py b/zerver/webhooks/gogs/tests.py index 507ba0f04b..66b793ccc8 100644 --- a/zerver/webhooks/gogs/tests.py +++ b/zerver/webhooks/gogs/tests.py @@ -63,27 +63,23 @@ class GogsHookTests(WebhookTestCase): def test_pull_request_opened(self) -> None: expected_topic = u"try-git / PR #1 Title Text for Pull Request" - expected_message = u"""john opened [PR #1](http://localhost:3000/john/try-git/pulls/1) -from `feature` to `master`""" + expected_message = u"""john opened [PR #1](http://localhost:3000/john/try-git/pulls/1) from `feature` to `master`.""" self.send_and_test_stream_message('pull_request_opened', expected_topic, expected_message, HTTP_X_GOGS_EVENT='pull_request') def test_pull_request_opened_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic='notifications') expected_topic = u"notifications" - expected_message = u"""john opened [PR #1 Title Text for Pull Request](http://localhost:3000/john/try-git/pulls/1) -from `feature` to `master`""" + expected_message = u"""john opened [PR #1 Title Text for Pull Request](http://localhost:3000/john/try-git/pulls/1) from `feature` to `master`.""" self.send_and_test_stream_message('pull_request_opened', expected_topic, expected_message, HTTP_X_GOGS_EVENT='pull_request') def test_pull_request_closed(self) -> None: expected_topic = u"try-git / PR #1 Title Text for Pull Request" - expected_message = u"""john closed [PR #1](http://localhost:3000/john/try-git/pulls/1) -from `feature` to `master`""" + expected_message = u"""john closed [PR #1](http://localhost:3000/john/try-git/pulls/1) from `feature` to `master`.""" self.send_and_test_stream_message('pull_request_closed', expected_topic, expected_message, HTTP_X_GOGS_EVENT='pull_request') def test_pull_request_merged(self) -> None: expected_topic = u"try-git / PR #2 Title Text for Pull Request" - expected_message = u"""john merged [PR #2](http://localhost:3000/john/try-git/pulls/2) -from `feature` to `master`""" + expected_message = u"""john merged [PR #2](http://localhost:3000/john/try-git/pulls/2) from `feature` to `master`.""" self.send_and_test_stream_message('pull_request_merged', expected_topic, expected_message, HTTP_X_GOGS_EVENT='pull_request') @patch('zerver.webhooks.gogs.view.check_send_webhook_message')