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 3 events.

Joelute75611c6ceedb
diff --git a/zerver/webhooks/bitbucket3/tests.py b/zerver/webhooks/bitbucket3/tests.py
index 534fd7725bd..be1be2e5708 100644
--- a/zerver/webhooks/bitbucket3/tests.py
+++ b/zerver/webhooks/bitbucket3/tests.py
@@ -158,12 +158,12 @@ class Bitbucket3HookTests(WebhookTestCase):
def test_pr_modified(self) -> None:
expected_topic = "sandbox / PR #1 Branch1"
- expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) modified [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) from `branch1` to `master` (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura)):\n\n~~~ quote\n* Add file2.txt\n* Add file3.txt\nBoth of these files would be important additions to the project!\n~~~"""
+ expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) modified [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura)):\n\n~~~ quote\n* Add file2.txt\n* Add file3.txt\nBoth of these files would be important additions to the project!\n~~~"""
self.check_webhook("pull_request_modified", expected_topic, expected_message)
def test_pr_modified_with_include_title(self) -> None:
expected_topic = "custom_topic"
- expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) modified [PR #1 Branch1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) from `branch1` to `master` (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura)):\n\n~~~ quote\n* Add file2.txt\n* Add file3.txt\nBoth of these files would be important additions to the project!\n~~~"""
+ expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) modified [PR #1 Branch1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura)):\n\n~~~ quote\n* Add file2.txt\n* Add file3.txt\nBoth of these files would be important additions to the project!\n~~~"""
self.url = self.build_webhook_url(topic="custom_topic")
self.check_webhook("pull_request_modified", expected_topic, expected_message)
@@ -185,7 +185,7 @@ class Bitbucket3HookTests(WebhookTestCase):
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) from `master` to `master`."""
self.check_webhook("pull_request_merged", expected_topic, expected_message)
# PR reviewer events:
diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.py
index d6812075e19..c3442fead38 100644
--- a/zerver/webhooks/bitbucket3/view.py
+++ b/zerver/webhooks/bitbucket3/view.py
@@ -250,6 +250,11 @@ def get_pr_opened_or_modified_body(
) -> str:
pr = payload["pullRequest"]
description = pr.get("description").tame(check_none_or(check_string))
+ target_branch = None
+ base_branch = None
+ if action == "opened":
+ target_branch = pr["fromRef"]["displayId"].tame(check_string)
+ base_branch = pr["toRef"]["displayId"].tame(check_string)
reviewers_string = get_assignees_string(pr)
return get_pull_request_event_message(
@@ -257,14 +262,27 @@ def get_pr_opened_or_modified_body(
action=action,
url=pr["links"]["self"][0]["href"].tame(check_string),
number=pr["id"].tame(check_int),
- target_branch=pr["fromRef"]["displayId"].tame(check_string),
- base_branch=pr["toRef"]["displayId"].tame(check_string),
+ target_branch=target_branch,
+ base_branch=base_branch,
message=description,
reviewer=reviewers_string if reviewers_string else None,
title=pr["title"].tame(check_string) if include_title else None,
)
+def get_pr_merged_body(payload: WildValue, action: str, include_title: Optional[str]) -> str:
+ pr = payload["pullRequest"]
+ return get_pull_request_event_message(
+ user_name=get_user_name(payload),
+ action=action,
+ url=pr["links"]["self"][0]["href"].tame(check_string),
+ number=pr["id"].tame(check_int),
+ target_branch=pr["fromRef"]["displayId"].tame(check_string),
+ base_branch=pr["toRef"]["displayId"].tame(check_string),
+ title=pr["title"].tame(check_string) if include_title else None,
+ )
+
+
def get_pr_needs_work_body(payload: WildValue, include_title: Optional[str]) -> str:
pr = payload["pullRequest"]
if not include_title:
@@ -331,6 +349,8 @@ def pr_handler(
)
if action in ["opened", "modified"]:
body = get_pr_opened_or_modified_body(payload, action, include_title)
+ elif action == "merged":
+ body = get_pr_merged_body(payload, action, include_title)
elif action == "needs_work":
body = get_pr_needs_work_body(payload, include_title)
elif action == "reviewers_updated":