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: Modify branch names for Bitbucket 2 events.

Joelute8747aa6fa1d6
diff --git a/zerver/webhooks/bitbucket2/tests.py b/zerver/webhooks/bitbucket2/tests.py
index 839b7b4c8a3..67574be62b2 100644
--- a/zerver/webhooks/bitbucket2/tests.py
+++ b/zerver/webhooks/bitbucket2/tests.py
@@ -145,7 +145,7 @@ class Bitbucket2HookTests(WebhookTestCase):
)
def test_bitbucket2_on_pull_request_updated_event(self) -> None:
- expected_message = "Tomasz updated [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 updated [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~"
self.check_webhook(
"pull_request_created_or_updated",
TOPIC_PR_EVENTS,
@@ -192,9 +192,7 @@ class Bitbucket2HookTests(WebhookTestCase):
)
def test_bitbucket2_on_pull_request_fulfilled_event(self) -> None:
- expected_message = (
- "Tomasz merged [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)."
- )
+ expected_message = "Tomasz merged [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master`."
self.check_webhook(
"pull_request_fulfilled_or_rejected",
TOPIC_PR_EVENTS,
diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.py
index ae2d8b952db..28586627fae 100644
--- a/zerver/webhooks/bitbucket2/view.py
+++ b/zerver/webhooks/bitbucket2/view.py
@@ -334,11 +334,19 @@ def get_issue_action_body(payload: WildValue, action: str, include_title: bool)
def get_pull_request_action_body(payload: WildValue, action: str, include_title: bool) -> str:
pull_request = payload["pullrequest"]
+ target_branch = None
+ base_branch = None
+ if action == "merged":
+ target_branch = pull_request["source"]["branch"]["name"].tame(check_string)
+ base_branch = pull_request["destination"]["branch"]["name"].tame(check_string)
+
return get_pull_request_event_message(
get_actor_info(payload),
action,
get_pull_request_url(pull_request),
pull_request["id"].tame(check_int),
+ target_branch=target_branch,
+ base_branch=base_branch,
title=pull_request["title"].tame(check_string) if include_title else None,
)
@@ -356,8 +364,12 @@ def get_pull_request_created_or_updated_body(
action,
get_pull_request_url(pull_request),
pull_request["id"].tame(check_int),
- target_branch=pull_request["source"]["branch"]["name"].tame(check_string),
- base_branch=pull_request["destination"]["branch"]["name"].tame(check_string),
+ target_branch=pull_request["source"]["branch"]["name"].tame(check_string)
+ if action == "created"
+ else None,
+ base_branch=pull_request["destination"]["branch"]["name"].tame(check_string)
+ if action == "created"
+ else None,
message=pull_request["description"].tame(check_string),
assignee=assignee,
title=pull_request["title"].tame(check_string) if include_title else None,