diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py index ebd246ca2c..34032f2be4 100644 --- a/zerver/webhooks/gitlab/tests.py +++ b/zerver/webhooks/gitlab/tests.py @@ -369,7 +369,7 @@ A trivial change that should probably be ignored. def test_merge_request_updated_event_message(self) -> None: expected_topic = "my-awesome-project / MR #3 New Merge Request" - expected_message = "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~~~" + expected_message = "Tomasz Kolek updated [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) (assigned to Tomasz Kolek):\n\n~~~ quote\nupdated desc\n~~~" self.check_webhook( "merge_request_hook__merge_request_updated", expected_topic, expected_message ) @@ -383,7 +383,7 @@ A trivial change that should probably be ignored. def test_merge_request_merged_event_message(self) -> None: expected_topic = "my-awesome-project / MR #3 New Merge Request" - expected_message = "Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)." + expected_message = "Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master`." self.check_webhook( "merge_request_hook__merge_request_merged", expected_topic, expected_message @@ -589,7 +589,7 @@ A trivial change that should probably be ignored. def test_system_merge_request_merged_event_message(self) -> None: expected_topic = "my-awesome-project / MR #3 New Merge Request" - expected_message = "Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)." + expected_message = "Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master`." self.check_webhook("system_hook__merge_request_merged", expected_topic, expected_message) diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index d961b89b2d..96984f84e1 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -132,11 +132,19 @@ def get_merge_request_updated_event_body(payload: WildValue, include_title: bool def get_merge_request_event_body(payload: WildValue, action: str, include_title: bool) -> str: pull_request = payload["object_attributes"] + target_branch = None + base_branch = None + if action == "merged": + target_branch = pull_request["source_branch"].tame(check_string) + base_branch = pull_request["target_branch"].tame(check_string) + return get_pull_request_event_message( get_issue_user_name(payload), action, pull_request["url"].tame(check_string), pull_request["iid"].tame(check_int), + target_branch=target_branch, + base_branch=base_branch, type="MR", title=payload["object_attributes"]["title"].tame(check_string) if include_title else None, ) @@ -151,8 +159,8 @@ def get_merge_request_open_or_updated_body( action, pull_request["url"].tame(check_string), pull_request["iid"].tame(check_int), - pull_request["source_branch"].tame(check_string), - pull_request["target_branch"].tame(check_string), + pull_request["source_branch"].tame(check_string) if action == "created" else None, + pull_request["target_branch"].tame(check_string) if action == "created" else None, pull_request["description"].tame(check_string), assignees=replace_assignees_username_with_name(get_assignees(payload)), type="MR",