Skip to content

armgit / zulip

Public Imported from GitHub
0

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

integration: Move assignee message to the end for git integrations.

Joelute4dc85dddc127
diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py
index 6e95d9e9d66..576aa37f319 100644
--- a/zerver/lib/webhooks/git.py
+++ b/zerver/lib/webhooks/git.py
@@ -190,6 +190,13 @@ def get_pull_request_event_message(
else:
main_message = PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE.format(**kwargs)
+ if target_branch and base_branch:
+ branch_info = PULL_REQUEST_BRANCH_INFO_TEMPLATE.format(
+ target=target_branch,
+ base=base_branch,
+ )
+ main_message = f"{main_message} {branch_info}"
+
if assignees:
assignees_string = ""
if len(assignees) == 1:
@@ -210,13 +217,6 @@ def get_pull_request_event_message(
assignee_info = PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE.format(assignee=assignee)
main_message = f"{main_message} {assignee_info}"
- if target_branch and base_branch:
- branch_info = PULL_REQUEST_BRANCH_INFO_TEMPLATE.format(
- target=target_branch,
- base=base_branch,
- )
- main_message = f"{main_message} {branch_info}"
-
punctuation = ":" if message else "."
if (
assignees
diff --git a/zerver/webhooks/bitbucket2/tests.py b/zerver/webhooks/bitbucket2/tests.py
index 67574be62b2..e2ac0387c66 100644
--- a/zerver/webhooks/bitbucket2/tests.py
+++ b/zerver/webhooks/bitbucket2/tests.py
@@ -116,7 +116,7 @@ class Bitbucket2HookTests(WebhookTestCase):
self.check_webhook("issue_commented", expected_topic, expected_message)
def test_bitbucket2_on_pull_request_created_event(self) -> None:
- expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to Tomasz Kolek) from `new-branch` to `master`:\n\n~~~ quote\ndescription\n~~~"
+ expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~"
self.check_webhook(
"pull_request_created_or_updated",
TOPIC_PR_EVENTS,
@@ -125,7 +125,7 @@ class Bitbucket2HookTests(WebhookTestCase):
)
def test_bitbucket2_on_pull_request_created_without_reviewer_username_event(self) -> None:
- expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to Tomasz Kolek) from `new-branch` to `master`:\n\n~~~ quote\ndescription\n~~~"
+ expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~"
self.check_webhook(
"pull_request_created_or_updated_without_username",
TOPIC_PR_EVENTS,
@@ -136,7 +136,7 @@ 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 = "notifications"
- expected_message = "Tomasz created [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to Tomasz Kolek) from `new-branch` to `master`:\n\n~~~ quote\ndescription\n~~~"
+ expected_message = "Tomasz created [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~"
self.check_webhook(
"pull_request_created_or_updated",
expected_topic,
diff --git a/zerver/webhooks/gitea/tests.py b/zerver/webhooks/gitea/tests.py
index c9988c314cf..4e6610be270 100644
--- a/zerver/webhooks/gitea/tests.py
+++ b/zerver/webhooks/gitea/tests.py
@@ -51,7 +51,7 @@ class GiteaHookTests(WebhookTestCase):
def test_pull_request_assigned(self) -> None:
expected_topic = "test / PR #1906 test 2"
- expected_message = """kostekIV assigned [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) (assigned to kostekIV) from `d` to `master`."""
+ expected_message = """kostekIV assigned [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master` (assigned to kostekIV)."""
self.check_webhook("pull_request__assigned", expected_topic, expected_message)
def test_issues_opened(self) -> None:
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py
index 93c2a6aedd4..72a4a02249a 100644
--- a/zerver/webhooks/github/tests.py
+++ b/zerver/webhooks/github/tests.py
@@ -162,7 +162,7 @@ class GitHubWebhookTest(WebhookTestCase):
def test_pull_request_opened_with_preassigned_assignee_msg(self) -> None:
expected_topic = "Scheduler / PR #4 Improve README"
- expected_message = "eeshangarg opened [PR #4](https://github.com/eeshangarg/Scheduler/pull/4) (assigned to eeshangarg) from `eeshangarg:improve-readme-2` to `eeshangarg:master`."
+ expected_message = "eeshangarg opened [PR #4](https://github.com/eeshangarg/Scheduler/pull/4) from `eeshangarg:improve-readme-2` to `eeshangarg:master` (assigned to eeshangarg)."
self.check_webhook(
"pull_request__opened_with_preassigned_assignee", expected_topic, expected_message
)
diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py
index 34032f2be4a..e14c2b811d4 100644
--- a/zerver/webhooks/gitlab/tests.py
+++ b/zerver/webhooks/gitlab/tests.py
@@ -304,7 +304,7 @@ class GitlabHookTests(WebhookTestCase):
def test_merge_request_created_with_assignee_event_message(self) -> None:
expected_topic = "my-awesome-project / MR #3 New Merge Request"
- expected_message = "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~~~"
+ expected_message = "Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription of merge request\n~~~"
self.check_webhook(
"merge_request_hook__merge_request_created_with_assignee",
expected_topic,
@@ -314,7 +314,7 @@ class GitlabHookTests(WebhookTestCase):
def test_merge_request_created_with_multiple_assignees_event_message(self) -> None:
expected_topic = "Demo Project / MR #1 Make a trivial change to the README."
expected_message = """
-Hemanth V. Alluri created [MR #1](https://gitlab.com/Hypro999/demo-project/-/merge_requests/1) (assigned to Hemanth V. Alluri and Hemanth V. Alluri) from `devel` to `master`:
+Hemanth V. Alluri created [MR #1](https://gitlab.com/Hypro999/demo-project/-/merge_requests/1) from `devel` to `master` (assigned to Hemanth V. Alluri and Hemanth V. Alluri):
~~~ quote
A trivial change that should probably be ignored.
@@ -576,7 +576,7 @@ A trivial change that should probably be ignored.
def test_system_merge_request_created_with_assignee_event_message(self) -> None:
expected_topic = "my-awesome-project / MR #3 New Merge Request"
- expected_message = "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~~~"
+ expected_message = "Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription of merge request\n~~~"
self.check_webhook(
"system_hook__merge_request_created_with_assignee", expected_topic, expected_message
)