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.

webhooks/gogs: Use pull request number instead of ID in topic.

0xthedance03992496fc42
diff --git a/static/images/integrations/gitea/001.png b/static/images/integrations/gitea/001.png
index a6dd9a084be..89a2909d917 100644
Binary files a/static/images/integrations/gitea/001.png and b/static/images/integrations/gitea/001.png differ
diff --git a/zerver/webhooks/gitea/fixtures/pull_request__merged.json b/zerver/webhooks/gitea/fixtures/pull_request__merged.json
index ff36828ad28..cb59b1f432f 100644
--- a/zerver/webhooks/gitea/fixtures/pull_request__merged.json
+++ b/zerver/webhooks/gitea/fixtures/pull_request__merged.json
@@ -5,7 +5,7 @@
"pull_request": {
"id": 1905,
"url": "https://try.gitea.io/kostekIV/test/pulls/4",
- "number": 1905,
+ "number": 4,
"user": {
"id": 21818,
"login": "kostekIV",
diff --git a/zerver/webhooks/gitea/tests.py b/zerver/webhooks/gitea/tests.py
index 7b8c8786d42..1d6b6ce5118 100644
--- a/zerver/webhooks/gitea/tests.py
+++ b/zerver/webhooks/gitea/tests.py
@@ -21,39 +21,39 @@ class GiteaHookTests(WebhookTestCase):
self.check_webhook("create__branch", expected_topic_name, expected_message)
def test_pull_request_opened(self) -> None:
- expected_topic_name = "test / PR #1905 New pr"
+ expected_topic_name = "test / PR #4 New pr"
expected_message = """kostekIV opened [PR #4](https://try.gitea.io/kostekIV/test/pulls/4) from `test-branch` to `master`."""
self.check_webhook("pull_request__opened", expected_topic_name, expected_message)
def test_pull_request_merged(self) -> None:
- expected_topic_name = "zulip-terminal / PR #1905 Fix remove-op on reaction event"
- expected_message = """kostekIV merged [PR #1905](https://try.gitea.io/kostekIV/test/pulls/4) from `reaction-metadata` to `main`."""
+ expected_topic_name = "zulip-terminal / PR #4 Fix remove-op on reaction event"
+ expected_message = """kostekIV merged [PR #4](https://try.gitea.io/kostekIV/test/pulls/4) from `reaction-metadata` to `main`."""
self.check_webhook("pull_request__merged", expected_topic_name, expected_message)
def test_pull_request_edited(self) -> None:
- expected_topic_name = "test / PR #1906 test 2"
+ expected_topic_name = "test / PR #5 test 2"
expected_message = (
"""kostekIV edited [PR #5](https://try.gitea.io/kostekIV/test/pulls/5)."""
)
self.check_webhook("pull_request__edited", expected_topic_name, expected_message)
def test_pull_request_reopened(self) -> None:
- expected_topic_name = "test / PR #1906 test 2"
+ expected_topic_name = "test / PR #5 test 2"
expected_message = """kostekIV reopened [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master`."""
self.check_webhook("pull_request__reopened", expected_topic_name, expected_message)
def test_pull_request_closed(self) -> None:
- expected_topic_name = "test / PR #1906 test 2"
+ expected_topic_name = "test / PR #5 test 2"
expected_message = """kostekIV closed [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master`."""
self.check_webhook("pull_request__closed", expected_topic_name, expected_message)
def test_pull_request_closed_different_user(self) -> None:
- expected_topic_name = "test / PR #126085 PR closed"
+ expected_topic_name = "test / PR #1 PR closed"
expected_message = """Aneesh-Hegde closed [PR #1](https://gitea.com/Aneesh-Hegde/test-repo/pulls/1) from `main` to `main`."""
self.check_webhook("pull_request__closed_diff_user", expected_topic_name, expected_message)
def test_pull_request_assigned(self) -> None:
- expected_topic_name = "test / PR #1906 test 2"
+ expected_topic_name = "test / PR #5 test 2"
expected_message = """kostekIV assigned kostekIV to [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_name, expected_message)
diff --git a/zerver/webhooks/gogs/tests.py b/zerver/webhooks/gogs/tests.py
index ee2d098e753..c08478b6c5f 100644
--- a/zerver/webhooks/gogs/tests.py
+++ b/zerver/webhooks/gogs/tests.py
@@ -79,22 +79,22 @@ class GogsHookTests(WebhookTestCase):
self.check_webhook("pull_request__merged", expected_topic_name, expected_message)
def test_pull_request_reopened(self) -> None:
- expected_topic_name = "test / PR #1349 reopened"
+ expected_topic_name = "test / PR #2 reopened"
expected_message = """kostekIV reopened [PR #2](https://try.gogs.io/kostekIV/test/pulls/2) from `c` to `master`."""
self.check_webhook("pull_request__reopened", expected_topic_name, expected_message)
def test_pull_request_edited(self) -> None:
- expected_topic_name = "test / PR #1349 Test"
+ expected_topic_name = "test / PR #2 Test"
expected_message = """kostekIV edited [PR #2](https://try.gogs.io/kostekIV/test/pulls/2)."""
self.check_webhook("pull_request__edited", expected_topic_name, expected_message)
def test_pull_request_assigned(self) -> None:
- expected_topic_name = "test / PR #1349 Test"
+ expected_topic_name = "test / PR #2 Test"
expected_message = """kostekIV assigned kostekIV to [PR #2](https://try.gogs.io/kostekIV/test/pulls/2) from `c` to `master`."""
self.check_webhook("pull_request__assigned", expected_topic_name, expected_message)
def test_pull_request_synchronized(self) -> None:
- expected_topic_name = "test / PR #1349 Test"
+ expected_topic_name = "test / PR #2 Test"
expected_message = """kostekIV synchronized [PR #2](https://try.gogs.io/kostekIV/test/pulls/2) from `c` to `master`."""
self.check_webhook("pull_request__synchronized", expected_topic_name, expected_message)
diff --git a/zerver/webhooks/gogs/view.py b/zerver/webhooks/gogs/view.py
index d74be6f4648..b191b8bb8cc 100644
--- a/zerver/webhooks/gogs/view.py
+++ b/zerver/webhooks/gogs/view.py
@@ -221,7 +221,7 @@ def gogs_webhook_main(
topic_name = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format(
repo=repo,
type="PR",
- id=payload["pull_request"]["id"].tame(check_int),
+ id=payload["pull_request"]["number"].tame(check_int),
title=payload["pull_request"]["title"].tame(check_string),
)
elif event == "issues":