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.

integrations: Modify URL for note events in GitLab Integration.

Satyam Bansal45757ca7a115
diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py
index 530433aa8fc..4f67c3877a2 100644
--- a/zerver/webhooks/gitlab/tests.py
+++ b/zerver/webhooks/gitlab/tests.py
@@ -231,13 +231,13 @@ class GitlabHookTests(WebhookTestCase):
def test_note_merge_request_event_message(self) -> None:
expected_topic = "testing-zulip-gitlab-integration / MR #1 add new-feature"
- expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~"
+ expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~"
self.check_webhook("note_hook__merge_request_note", expected_topic, expected_message)
def test_note_merge_request_event_message_without_merge_request_title(self) -> None:
expected_topic = "testing-zulip-gitlab-integration / MR #1"
- expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~"
+ expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~"
# To keep things as valid JSON.
self.url = self.build_webhook_url(use_merge_request_title="false")
self.check_webhook("note_hook__merge_request_note", expected_topic, expected_message)
@@ -245,45 +245,45 @@ class GitlabHookTests(WebhookTestCase):
def test_note_merge_request_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic = "notifications"
- expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1 add new-feature](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~"
+ expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1 add new-feature](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~"
self.check_webhook("note_hook__merge_request_note", expected_topic, expected_message)
def test_note_issue_event_message(self) -> None:
expected_topic = "testing-zulip-gitlab-integration / issue #1 Add more lines"
- expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406279810) on [issue #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/issues/1):\n\n~~~ quote\nThis is again a random comment.\n~~~"
+ expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406279810) on [issue #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1):\n\n~~~ quote\nThis is again a random comment.\n~~~"
self.check_webhook("note_hook__issue_note", expected_topic, expected_message)
def test_note_confidential_issue_event_message(self) -> None:
expected_subject = "testing-zulip-gitlab-integration / issue #1 Add more lines"
- expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406130881) on [issue #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/issues/1):\n\n~~~ quote\nSome more comments\n~~~"
+ expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406130881) on [issue #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1):\n\n~~~ quote\nSome more comments\n~~~"
self.check_webhook("note_hook__confidential_issue_note", expected_subject, expected_message)
def test_note_issue_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic = "notifications"
- expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406279810) on [issue #1 Add more lines](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/issues/1):\n\n~~~ quote\nThis is again a random comment.\n~~~"
+ expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406279810) on [issue #1 Add more lines](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1):\n\n~~~ quote\nThis is again a random comment.\n~~~"
self.check_webhook("note_hook__issue_note", expected_topic, expected_message)
def test_note_snippet_old_event_message(self) -> None:
expected_topic = "my-awesome-project / snippet #2 test"
- expected_message = "Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [snippet #2](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2):\n\n~~~ quote\nNice snippet\n~~~"
+ expected_message = "Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [snippet #2](https://gitlab.com/tomaszkolek0/my-awesome-project/-/snippets/2):\n\n~~~ quote\nNice snippet\n~~~"
self.check_webhook("note_hook__snippet_note_old", expected_topic, expected_message)
def test_note_snippet_event_message(self) -> None:
expected_topic = "testing-zulip-gitlab-integration / snippet #2547713 a ver..."
- expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713#note_1424268837) on [snippet #2547713](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/snippets/2547713):\n\n~~~ quote\nsome comment\n~~~"
+ expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713#note_1424268837) on [snippet #2547713](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713):\n\n~~~ quote\nsome comment\n~~~"
self.check_webhook("note_hook__snippet_note", expected_topic, expected_message)
def test_note_snippet_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic = "notifications"
- expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713#note_1424268837) on [snippet #2547713 a very new new feature](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/snippets/2547713):\n\n~~~ quote\nsome comment\n~~~"
+ expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713#note_1424268837) on [snippet #2547713 a very new new feature](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713):\n\n~~~ quote\nsome comment\n~~~"
self.check_webhook("note_hook__snippet_note", expected_topic, expected_message)
diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py
index 4c4c0db5277..3d4b64304e6 100644
--- a/zerver/webhooks/gitlab/view.py
+++ b/zerver/webhooks/gitlab/view.py
@@ -216,10 +216,7 @@ def get_commented_commit_event_body(payload: WildValue, include_title: bool) ->
def get_commented_merge_request_event_body(payload: WildValue, include_title: bool) -> str:
comment = payload["object_attributes"]
action = "[commented]({}) on".format(comment["url"].tame(check_string))
- url = "{}/merge_requests/{}".format(
- payload["project"]["web_url"].tame(check_string),
- payload["merge_request"]["iid"].tame(check_int),
- )
+ url = payload["merge_request"]["url"].tame(check_string)
return get_pull_request_event_message(
user_name=get_issue_user_name(payload),
@@ -235,10 +232,7 @@ def get_commented_merge_request_event_body(payload: WildValue, include_title: bo
def get_commented_issue_event_body(payload: WildValue, include_title: bool) -> str:
comment = payload["object_attributes"]
action = "[commented]({}) on".format(comment["url"].tame(check_string))
- url = "{}/issues/{}".format(
- payload["project"]["web_url"].tame(check_string),
- payload["issue"]["iid"].tame(check_int),
- )
+ url = payload["issue"]["url"].tame(check_string)
return get_pull_request_event_message(
user_name=get_issue_user_name(payload),
@@ -254,10 +248,14 @@ def get_commented_issue_event_body(payload: WildValue, include_title: bool) -> s
def get_commented_snippet_event_body(payload: WildValue, include_title: bool) -> str:
comment = payload["object_attributes"]
action = "[commented]({}) on".format(comment["url"].tame(check_string))
- url = "{}/snippets/{}".format(
- payload["project"]["web_url"].tame(check_string),
- payload["snippet"]["id"].tame(check_int),
- )
+ # Snippet URL is only available in GitLab 16.1+
+ if "url" in payload["snippet"]:
+ url = payload["snippet"]["url"].tame(check_string)
+ else:
+ url = "{}/-/snippets/{}".format(
+ payload["project"]["web_url"].tame(check_string),
+ payload["snippet"]["id"].tame(check_int),
+ )
return get_pull_request_event_message(
user_name=get_issue_user_name(payload),