Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
from unittest.mock import MagicMock, patch
import orjson
from zerver.actions.custom_profile_fields import try_add_realm_default_custom_profile_field
from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.webhooks.git import COMMITS_LIMIT
from zerver.models.realms import get_realm
class GitlabHookTests(WebhookTestCase):
def test_push_event_specified_topic(self) -> None:
self.url = self.build_webhook_url("topic=Specific%20topic")
expected_topic_name = "Specific topic"
expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"
self.check_webhook("push_hook", expected_topic_name, expected_message)
def test_push_event_message(self) -> None:
expected_topic_name = "my-awesome-project / tomek"
expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"
self.check_webhook("push_hook", expected_topic_name, expected_message)
def test_push_event_private_project_ignored(self) -> None:
self.url = self.build_webhook_url(ignore_private_projects="true")
self.check_webhook(fixture_name="push_hook", expect_noop=True)
def test_push_local_branch_without_commits(self) -> None:
expected_topic_name = "my-awesome-project / changes"
expected_message = "Eeshan Garg [pushed](https://gitlab.com/eeshangarg/my-awesome-project/-/compare/0000000000000000000000000000000000000000...68d7a5528cf423dfaac37dd62a56ac9cc8a884e3) the branch changes."
self.check_webhook(
"push_hook__push_local_branch_without_commits", expected_topic_name, expected_message
)
def test_push_event_message_filtered_by_branches(self) -> None:
self.url = self.build_webhook_url(branches="master,tomek")
expected_topic_name = "my-awesome-project / tomek"
expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"
self.check_webhook("push_hook", expected_topic_name, expected_message)
def test_push_multiple_committers(self) -> None:
expected_topic_name = "my-awesome-project / tomek"
expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek. Commits by Ben (1) and Tomasz Kolek (1).\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"
self.check_webhook(
"push_hook__push_multiple_committers", expected_topic_name, expected_message
)
def test_push_multiple_committers_with_others(self) -> None:
expected_topic_name = "my-awesome-project / tomek"
commit_info = "* b ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))\n"
expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 7 commits to branch tomek. Commits by Ben (3), baxterthehacker (2), James (1) and others (1).\n\n{commit_info * 6}* b ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"
self.check_webhook(
"push_hook__push_multiple_committers_with_others", expected_topic_name, expected_message
)
def test_push_commits_more_than_limit_event_message(self) -> None:
expected_topic_name = "my-awesome-project / tomek"
commits_info = "* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n"
expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]"
self.check_webhook(
"push_hook__push_commits_more_than_limit", expected_topic_name, expected_message
)
def test_push_commits_more_than_limit_message_filtered_by_branches(self) -> None:
self.url = self.build_webhook_url(branches="master,tomek")
expected_topic_name = "my-awesome-project / tomek"
commits_info = "* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n"
expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]"
self.check_webhook(
"push_hook__push_commits_more_than_limit", expected_topic_name, expected_message
)
def test_remove_branch_event_message(self) -> None:
expected_topic_name = "my-awesome-project / tomek"
expected_message = "Tomasz Kolek deleted branch tomek."
self.check_webhook("push_hook__remove_branch", expected_topic_name, expected_message)
def test_tag_push_event_messages(self) -> None:
expected_topic_name = "my-awesome-project"
payload = orjson.loads(self.get_body("tag_push_hook"))
test_cases = [
(payload["checkout_sha"], "Tomasz Kolek pushed tag xyz."),
(None, "Tomasz Kolek removed tag xyz."),
]
for checkout_sha, expected_message in test_cases:
with self.subTest(checkout_sha=checkout_sha):
payload["checkout_sha"] = checkout_sha
self.check_webhook(
"tag_push_hook", expected_topic_name, expected_message, custom_payload=payload
)
def test_create_issue_without_assignee_event_message(self) -> None:
expected_topic_name = "my-awesome-project / issue #1 Issue title"
expected_message = "Tomasz Kolek created [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1):\n\n``` quote\nIssue description\n```"
self.check_webhook(
"issue_hook__issue_created_without_assignee", expected_topic_name, expected_message
)
def test_create_confidential_issue_without_assignee_event_message(self) -> None:
expected_subject = "testing / issue #1 Testing"
expected_message = "Joe Bloggs created [issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1):\n\n``` quote\nTesting\n```"
self.check_webhook(
"confidential_issue_hook__issue_created_without_assignee",
expected_subject,
expected_message,
)
def test_create_issue_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [issue #1 Issue title](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1):\n\n``` quote\nIssue description\n```"
self.check_webhook(
"issue_hook__issue_created_without_assignee", expected_topic_name, expected_message
)
def test_create_issue_with_assignee_event_message(self) -> None:
expected_topic_name = "my-awesome-project / issue #1 Issue title"
expected_message = "Tomasz Kolek created [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1) (assigned to Tomasz Kolek):\n\n``` quote\nIssue description\n```"
self.check_webhook(
"issue_hook__issue_created_with_assignee", expected_topic_name, expected_message
)
def test_create_issue_with_two_assignees_event_message(self) -> None:
expected_subject = "Zulip GitLab Test / issue #2 Zulip Test Issue 2"
expected_message = "Adam Birds created [issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2) (assigned to Adam Birds and Eeshan Garg):\n\n``` quote\nZulip Test Issue 2\n```"
self.check_webhook(
"issue_hook__issue_created_with_two_assignees", expected_subject, expected_message
)
def test_create_issue_with_three_assignees_event_message(self) -> None:
expected_subject = "Zulip GitLab Test / issue #2 Zulip Test Issue 2"
expected_message = "Adam Birds created [issue #2](https://gitlab.com/adambirds/zulip-gitlab-test/issues/2) (assigned to Adam Birds, Eeshan Garg and Tim Abbott):\n\n``` quote\nZulip Test Issue 2\n```"
self.check_webhook(
"issue_hook__issue_created_with_three_assignees", expected_subject, expected_message
)
def test_create_confidential_issue_with_assignee_event_message(self) -> None:
expected_subject = "testing / issue #2 Testing"
expected_message = "Joe Bloggs created [issue #2](https://gitlab.example.co.uk/joe.bloggs/testing/issues/2) (assigned to Joe Bloggs):\n\n``` quote\nTesting\n```"
self.check_webhook(
"confidential_issue_hook__issue_created_with_assignee",
expected_subject,
expected_message,
)
def test_create_issue_with_hidden_comment_in_description(self) -> None:
expected_topic_name = "public-repo / issue #3 New Issue with hidden comment"
expected_message = "Eeshan Garg created [issue #3](https://gitlab.com/eeshangarg/public-repo/issues/3):\n\n``` quote\nThis description actually has a hidden comment in it!\n```"
self.check_webhook(
"issue_hook__issue_created_with_hidden_comment_in_description",
expected_topic_name,
expected_message,
)
def test_create_confidential_issue_with_hidden_comment_in_description(self) -> None:
expected_subject = "testing / issue #1 Testing"
expected_message = "Joe Bloggs created [issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1):\n\n``` quote\nThis description actually has a hidden comment in it!\n```"
self.check_webhook(
"confidential_issue_hook__issue_created_with_hidden_comment_in_description",
expected_subject,
expected_message,
)
def test_create_issue_with_null_description(self) -> None:
expected_topic_name = "my-awesome-project / issue #7 Issue without description"
expected_message = "Eeshan Garg created [issue #7](https://gitlab.com/eeshangarg/my-awesome-project/issues/7)."
self.check_webhook(
"issue_hook__issue_opened_with_null_description", expected_topic_name, expected_message
)
def test_update_issue_event_message(self) -> None:
expected_topic_name = "my-awesome-project / issue #1 Issue title_new"
expected_message = "Tomasz Kolek updated [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
self.check_webhook("issue_hook__issue_updated", expected_topic_name, expected_message)
def test_update_confidential_issue_event_message(self) -> None:
expected_subject = "testing / issue #1 Testing"
expected_message = "Joe Bloggs updated [issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)."
self.check_webhook(
"confidential_issue_hook__issue_updated", expected_subject, expected_message
)
def test_update_issue_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek updated [issue #1 Issue title_new](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
self.check_webhook("issue_hook__issue_updated", expected_topic_name, expected_message)
def test_close_issue_event_message(self) -> None:
expected_topic_name = "my-awesome-project / issue #1 Issue title_new"
expected_message = "Tomasz Kolek closed [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
self.check_webhook("issue_hook__issue_closed", expected_topic_name, expected_message)
def test_close_confidential_issue_event_message(self) -> None:
expected_subject = "testing / issue #1 Testing Test"
expected_message = "Joe Bloggs closed [issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)."
self.check_webhook(
"confidential_issue_hook__issue_closed", expected_subject, expected_message
)
def test_reopen_issue_event_message(self) -> None:
expected_topic_name = "my-awesome-project / issue #1 Issue title_new"
expected_message = "Tomasz Kolek reopened [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
self.check_webhook("issue_hook__issue_reopened", expected_topic_name, expected_message)
def test_reopen_confidential_issue_event_message(self) -> None:
expected_subject = "testing / issue #1 Testing Test"
expected_message = "Joe Bloggs reopened [issue #1](https://gitlab.example.co.uk/joe.bloggs/testing/issues/1)."
self.check_webhook(
"confidential_issue_hook__issue_reopened", expected_subject, expected_message
)
def test_note_commit_event_message(self) -> None:
expected_topic_name = "testing-zulip-gitlab-integration"
expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/commit/82689ddf00fd7bdadb5c2afb3b94bd555edc9d01#note_1406241063) on [82689ddf00f](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/commit/82689ddf00fd7bdadb5c2afb3b94bd555edc9d01):\n``` quote\nWow what a beautiful commit.\n```"
self.check_webhook("note_hook__commit_note", expected_topic_name, expected_message)
def test_note_merge_request_event_message(self) -> None:
expected_topic_name = "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):\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_name, expected_message)
def test_note_merge_request_event_message_without_merge_request_title(self) -> None:
expected_topic_name = "testing-zulip-gitlab-integration / MR #1"
expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457):\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_name, expected_message)
def test_note_merge_request_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "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```"
self.check_webhook("note_hook__merge_request_note", expected_topic_name, expected_message)
def test_note_issue_event_message(self) -> None:
expected_topic_name = "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):\n\n``` quote\nThis is again a random comment.\n```"
self.check_webhook("note_hook__issue_note", expected_topic_name, expected_message)
def test_note_design_event_message(self) -> None:
expected_topic_name = "testing-zulip-gitlab-integration / design Screenshot.png"
expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1/designs/Screenshot.png#note_1458583152):\n\n``` quote\nhello\n```"
self.check_webhook("note_hook__design_note", expected_topic_name, 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):\n\n``` quote\nSome more comments\n```"
self.check_webhook("confidential_note_hook__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_name = "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```"
self.check_webhook("note_hook__issue_note", expected_topic_name, expected_message)
def test_note_design_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "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/designs/Screenshot.png#note_1458583152) on design [Screenshot.png](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1/designs/Screenshot.png):\n\n``` quote\nhello\n```"
self.check_webhook("note_hook__design_note", expected_topic_name, expected_message)
def test_note_snippet_old_event_message(self) -> None:
expected_topic_name = "my-awesome-project / snippet #2 test"
expected_message = "Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058):\n\n``` quote\nNice snippet\n```"
self.check_webhook("note_hook__snippet_note_old", expected_topic_name, expected_message)
def test_note_snippet_event_message(self) -> None:
expected_topic_name = "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):\n\n``` quote\nsome comment\n```"
self.check_webhook("note_hook__snippet_note", expected_topic_name, expected_message)
def test_note_snippet_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "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```"
self.check_webhook("note_hook__snippet_note", expected_topic_name, expected_message)
def test_merge_request_created_without_assignee_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #2 NEW MR"
expected_message = "Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n``` quote\ndescription of merge request\n```"
self.check_webhook(
"merge_request_hook__merge_request_created_without_assignee",
expected_topic_name,
expected_message,
)
def test_merge_request_created_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n``` quote\ndescription of merge request\n```"
self.check_webhook(
"merge_request_hook__merge_request_created_without_assignee",
expected_topic_name,
expected_message,
)
def test_merge_request_created_with_assignee_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #3 New Merge Request"
expected_message = "Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master` (assigned to Tomasz Kolek):\n\n``` quote\ndescription of merge request\n```"
self.check_webhook(
"merge_request_hook__merge_request_created_with_assignee",
expected_topic_name,
expected_message,
)
def test_merge_request_created_with_multiple_assignees_event_message(self) -> None:
expected_topic_name = "Demo Project / MR #1 Make a trivial change to the README."
expected_message = """
Hemanth V. Alluri created [MR #1](https://gitlab.com/Hypro999/demo-project/-/merge_requests/1) from `devel` to `master` (assigned to Hemanth V. Alluri and Hemanth V. Alluri):
``` quote
A trivial change that should probably be ignored.
```
""".strip()
self.check_webhook(
"merge_request_hook__merge_request_created_with_multiple_assignees",
expected_topic_name,
expected_message,
)
def test_merge_request_closed_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #2 NEW MR"
expected_message = "Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)."
self.check_webhook(
"merge_request_hook__merge_request_closed", expected_topic_name, expected_message
)
def test_merge_request_closed_event_message_without_using_title(self) -> None:
expected_topic_name = "my-awesome-project / MR #2"
expected_message = "Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)."
self.url = self.build_webhook_url(use_merge_request_title="false")
self.check_webhook(
"merge_request_hook__merge_request_closed", expected_topic_name, expected_message
)
def test_merge_request_closed_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)."
self.check_webhook(
"merge_request_hook__merge_request_closed", expected_topic_name, expected_message
)
def test_merge_request_reopened_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #1 Update the README with author ..."
expected_message = "Eeshan Garg reopened [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)."
self.check_webhook(
"merge_request_hook__merge_request_reopened", expected_topic_name, expected_message
)
def test_merge_request_approved_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #1 Update the README with author ..."
expected_message = "Eeshan Garg approved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)."
self.check_webhook(
"merge_request_hook__merge_request_approved", expected_topic_name, expected_message
)
def test_merge_request_approval_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #1 Update the README"
expected_message = "Sumit Bhanushali added their approval for [MR #1](https://gitlab.com/sumitb16/my-awesome-project/merge_requests/1)."
self.check_webhook(
"merge_request_hook__merge_request_approval", expected_topic_name, expected_message
)
def test_merge_request_unapproval_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #1 Update the README"
expected_message = "Sumit Bhanushali removed their approval for [MR #1](https://gitlab.com/sumitb16/my-awesome-project/merge_requests/1)."
self.check_webhook(
"merge_request_hook__merge_request_unapproval", expected_topic_name, expected_message
)
def test_merge_request_updated_event_message(self) -> None:
expected_topic_name = "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):\n\n``` quote\nupdated desc\n```"
self.check_webhook(
"merge_request_hook__merge_request_updated", expected_topic_name, expected_message
)
def test_merge_request_added_commit_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #3 New Merge Request"
expected_message = "Tomasz Kolek added commit(s) to [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)."
self.check_webhook(
"merge_request_hook__merge_request_added_commit", expected_topic_name, expected_message
)
def test_merge_request_merged_event_message(self) -> None:
expected_topic_name = "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) from `tomek` to `master`."
self.check_webhook(
"merge_request_hook__merge_request_merged", expected_topic_name, expected_message
)
def test_merge_request_merged_event_message_ignored(self) -> None:
self.url = self.build_webhook_url(ignore_private_projects="true")
self.check_webhook(
fixture_name="merge_request_hook__merge_request_merged",
expect_noop=True,
)
def test_wiki_page_event_messages(self) -> None:
wiki_page_link = (
'[wiki page "how to"](https://gitlab.com/tomaszkolek0/my-awesome-project/wikis/how-to)'
)
expected_topic_name = "my-awesome-project"
test_cases = [
("create", f"Tomasz Kolek created {wiki_page_link}."),
("update", f"Tomasz Kolek updated {wiki_page_link}."),
]
payload = orjson.loads(self.get_body("wiki_page_hook"))
for action, expected_message in test_cases:
with self.subTest(action=action):
payload["object_attributes"]["action"] = action
self.check_webhook(
"wiki_page_hook",
expected_topic_name,
expected_message,
custom_payload=payload,
)
def test_pipeline_with_artifacts_event_message(self) -> None:
expected_topic_name = "onlysomeproject / test/links-in-zulip-pipeline-message"
expected_message = "[Pipeline (22668)](https://gitlab.example.com/group1/onlysomeproject/-/pipelines/22668) changed status to success with build(s):\n* [cleanup:cleanup docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58592) - success\n* [pages](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591) - success\n * built artifact: *artifacts.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/download)]\n* [black+pytest:future environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58590) - success\n* [docs:anaconda environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589) - success\n * built artifact: *sphinx-docs.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/download)]\n* [pytest:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58588) - success\n* [black:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58587) - success\n* [setup:docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58586) - success."
self.check_webhook(
"pipeline_hook__with_artifacts",
expected_topic_name,
expected_message,
)
def test_pipeline_event_messages(self) -> None:
pipeline_link = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206)"
job_link = "[job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112)"
job2_link = "[job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113)"
expected_topic_name = "my-awesome-project / master"
# Each case is a pipeline status, the status of each of the
# pipeline's builds keyed by build name, and the expected message.
test_cases = [
(
"pending",
{"job_name2": "pending", "job_name": "created"},
f"{pipeline_link} was created with build(s):\n* {job2_link} - pending\n* {job_link} - created.",
),
(
"running",
{"job_name2": "pending", "job_name": "running"},
f"{pipeline_link} started with build(s):\n* {job2_link} - pending\n* {job_link} - running.",
),
(
"success",
{"job_name2": "success", "job_name": "success"},
f"{pipeline_link} changed status to success with build(s):\n* {job2_link} - success\n* {job_link} - success.",
),
]
payload = orjson.loads(self.get_body("pipeline_hook"))
for pipeline_status, build_statuses, expected_message in test_cases:
with self.subTest(pipeline_status=pipeline_status):
payload["object_attributes"]["status"] = pipeline_status
for build in payload["builds"]:
build["status"] = build_statuses[build["name"]]
self.check_webhook(
"pipeline_hook",
expected_topic_name,
expected_message,
custom_payload=payload,
)
def test_issue_type_test_payload(self) -> None:
expected_topic_name = "public-repo"
expected_message = "Webhook for **public-repo** has been configured successfully! :tada:"
self.check_webhook(
"test_hook__issue_test_payload",
expected_topic_name,
expected_message,
)
@patch("zerver.lib.webhooks.common.check_send_webhook_message")
def test_push_event_message_filtered_by_branches_ignore(
self, check_send_webhook_message_mock: MagicMock
) -> None:
self.url = self.build_webhook_url(branches="master,development")
payload = self.get_body("push_hook")
result = self.client_post(
self.url, payload, HTTP_X_GITLAB_EVENT="Push Hook", content_type="application/json"
)
self.assertFalse(check_send_webhook_message_mock.called)
self.assert_json_success(result)
@patch("zerver.lib.webhooks.common.check_send_webhook_message")
def test_push_commits_more_than_limit_message_filtered_by_branches_ignore(
self, check_send_webhook_message_mock: MagicMock
) -> None:
self.url = self.build_webhook_url(branches="master,development")
payload = self.get_body("push_hook__push_commits_more_than_limit")
result = self.client_post(
self.url, payload, HTTP_X_GITLAB_EVENT="Push Hook", content_type="application/json"
)
self.assertFalse(check_send_webhook_message_mock.called)
self.assert_json_success(result)
def test_job_event_message_by_build_status(self) -> None:
expected_topic_name = "TEST-1 / master"
test_cases = [
("created", "Build build-job from build stage was created."),
("running", "Build build-job from build stage started."),
("success", "Build build-job from build stage changed status to success."),
("failed", "Build build-job from build stage changed status to failed."),
]
payload = orjson.loads(self.get_body("job_hook"))
for build_status, expected_message in test_cases:
with self.subTest(build_status=build_status):
payload["build_status"] = build_status
self.check_webhook(
"job_hook",
expected_topic_name,
expected_message,
custom_payload=payload,
)
def test_job_event_message_without_project_field_with_custom_topic(self) -> None:
self.url = self.build_webhook_url(topic="provided topic")
expected_topic_name = "provided topic"
expected_message = "[[TEST-1](https://gitlab.com/HydrallHarsh/test-1)] Build build-job from build stage was created."
# The project link falls back to the `repository` section for
# payloads that have no `project` section.
payload = orjson.loads(self.get_body("job_hook"))
del payload["project"]
self.check_webhook(
"job_hook", expected_topic_name, expected_message, custom_payload=payload
)
def test_system_push_event_message(self) -> None:
expected_topic_name = "gitlab / master"
expected_message = "John Smith [pushed](http://test.example.com/gitlab/gitlab/-/compare/95790bf891e76fee5e1747ab589903a6a1f80f22...da1560886d4f094c3e6c9ef40349f7d38b5d27d7) 1 commit to branch master. Commits by Test User (1).\n\n* Add simple search to projects in public area ([c5feabde2d8](https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428))"
self.check_webhook("system_hook__push_hook", expected_topic_name, expected_message)
def test_system_merge_request_created_without_assignee_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #2 NEW MR"
expected_message = "Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n``` quote\ndescription of merge request\n```"
self.check_webhook(
"system_hook__merge_request_created_without_assignee",
expected_topic_name,
expected_message,
)
def test_system_merge_request_created_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n``` quote\ndescription of merge request\n```"
self.check_webhook(
"system_hook__merge_request_created_without_assignee",
expected_topic_name,
expected_message,
)
def test_system_merge_request_created_with_assignee_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #3 New Merge Request"
expected_message = "Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master` (assigned to Tomasz Kolek):\n\n``` quote\ndescription of merge request\n```"
self.check_webhook(
"system_hook__merge_request_created_with_assignee",
expected_topic_name,
expected_message,
)
def test_system_merge_request_closed_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #2 NEW MR"
expected_message = "Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)."
self.check_webhook(
"system_hook__merge_request_closed", expected_topic_name, expected_message
)
def test_system_merge_request_merged_event_message(self) -> None:
expected_topic_name = "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) from `tomek` to `master`."
self.check_webhook(
"system_hook__merge_request_merged", expected_topic_name, expected_message
)
def test_system_merge_request_closed_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)."
self.check_webhook(
"system_hook__merge_request_closed", expected_topic_name, expected_message
)
def test_merge_request_unapproved_event_message(self) -> None:
expected_topic_name = "my-awesome-project / MR #1 Update the README with author ..."
expected_message = "Eeshan Garg unapproved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)."
self.check_webhook(
"merge_request_hook__merge_request_unapproved", expected_topic_name, expected_message
)
def test_release_event_messages(self) -> None:
release_url = "https://example.com/gitlab-org/release-webhook-example/-/releases/v1.1"
release_description = "\n``` quote\n## v1.1 (2024-09-06)\n\n- Feature added\n```"
expected_topic_name = "release-webhook-example"
test_cases = [
(
"create",
f"Release [v1.1]({release_url}) for tag v1.1 was created.{release_description}",
),
(
"update",
f"Release [v1.1]({release_url}) for tag v1.1 was updated.{release_description}",
),
("delete", "Release v1.1 for tag v1.1 was deleted."),
]
payload = orjson.loads(self.get_body("release_hook"))
for action, expected_message in test_cases:
with self.subTest(action=action):
payload["action"] = action
self.check_webhook(
"release_hook", expected_topic_name, expected_message, custom_payload=payload
)
def test_release_created_event_message_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url("topic=Specific%20topic")
expected_topic_name = "Specific topic"
expected_message = "[[release-webhook-example](https://example.com/gitlab-org/release-webhook-example)] Release [v1.1](https://example.com/gitlab-org/release-webhook-example/-/releases/v1.1) for tag v1.1 was created.\n``` quote\n## v1.1 (2024-09-06)\n\n- Feature added\n```"
self.check_webhook("release_hook", expected_topic_name, expected_message)
def test_feature_flag_event_messages(self) -> None:
feature_flag_link = (
"[sample-feature-flag](https://gitlab.com/kolanuvarun/sample/-/feature_flags)"
)
expected_topic_name = "sample"
test_cases = [
(True, f"Varun Kolanu activated the feature flag {feature_flag_link}."),
(False, f"Varun Kolanu deactivated the feature flag {feature_flag_link}."),
]
payload = orjson.loads(self.get_body("feature_flag_hook"))
for active, expected_message in test_cases:
with self.subTest(active=active):
payload["object_attributes"]["active"] = active
self.check_webhook(
"feature_flag_hook",
expected_topic_name,
expected_message,
custom_payload=payload,
)
def test_resource_access_token_project_expiry(self) -> None:
expected_topic_name = "Flight"
expected_message = "The access token [acd](https://example.com/flightjs/Flight/-/settings/access_tokens) will expire on Jan 26, 2024."
self.check_webhook(
"resource_access_token_hook__project_expiry", expected_topic_name, expected_message
)
def test_resource_access_token_group_expiry(self) -> None:
expected_topic_name = "Twitter"
expected_message = "The access token [acd](https://gitlab.com/groups/twitter/-/settings/access_tokens) will expire on Jan 26, 2024."
self.check_webhook(
"resource_access_token_hook__group_expiry", expected_topic_name, expected_message
)
def test_resource_access_token_group_expiry_with_custom_topic(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[Twitter](https://gitlab.com/groups/twitter)] The access token [acd](https://gitlab.com/groups/twitter/-/settings/access_tokens) will expire on Jan 26, 2024."
self.check_webhook(
"resource_access_token_hook__group_expiry", expected_topic_name, expected_message
)
def test_deployment_event_message_by_status(self) -> None:
deployment_url = "https://gitlab.com/vedant8600317/test/-/jobs/9905389091"
expected_topic_name = "test / production"
test_cases = [
(
"running",
f"[Vedant Joshi](https://gitlab.com/theofficialvedantjoshi) started a new [deployment]({deployment_url}):\n> [5879366](https://gitlab.com/vedant8600317/test/-/commit/58793660b22d6ceacbdc23b28a0562bca339702c) Update .gitlab-ci.yml file",
),
("success", f"The [deployment]({deployment_url}) was successful."),
("failed", f"The [deployment]({deployment_url}) failed."),
("canceled", f"The [deployment]({deployment_url}) was canceled."),
(
"blocked",
f"The [deployment]({deployment_url}) is blocked and awaiting manual action.",
),
]
payload = orjson.loads(self.get_body("deployment_hook"))
for status, expected_message in test_cases:
with self.subTest(status=status):
payload["status"] = status
self.check_webhook(
"deployment_hook",
expected_topic_name,
expected_message,
custom_payload=payload,
)
def test_deployment_event_with_unsupported_status(self) -> None:
payload_data = orjson.loads(
self.webhook_fixture_data(self.webhook_dir_name, "deployment_hook")
)
payload_data["status"] = "skipped"
result = self.client_post(
self.url,
orjson.dumps(payload_data),
content_type="application/json",
HTTP_X_GITLAB_EVENT="Deployment Hook",
)
self.assert_json_success(result)
self.assert_in_response(
"The 'Deployment Hook skipped' event isn't currently supported by the GitLab webhook; ignoring",
result,
)
def test_deployment_approval_event_message(self) -> None:
deployment_url = (
"https://gitlab.com/pritesh-30-group/deployment-webhook-test/-/jobs/15664214926"
)
expected_topic_name = "deployment-webhook-test / production"
# Status, comment, expected message
test_cases = [
(
"approved",
"Approval granted",
f"Pritesh-30 approved the [deployment]({deployment_url}).\n``` quote\nApproval granted\n```",
),
("approved", "", f"Pritesh-30 approved the [deployment]({deployment_url})."),
(
"rejected",
"Not ready to ship",
f"Pritesh-30 rejected the [deployment]({deployment_url}).\n``` quote\nNot ready to ship\n```",
),
("rejected", "", f"Pritesh-30 rejected the [deployment]({deployment_url})."),
]
payload = orjson.loads(self.get_body("deployment_hook__approval"))
for status, comment, expected_message in test_cases:
with self.subTest(status=status):
payload["status"] = status
payload["approval"]["status"] = status
payload["approval"]["comment"] = comment
self.check_webhook(
"deployment_hook__approval",
expected_topic_name,
expected_message,
custom_payload=payload,
)
def test_deployment_approval_event_message_silent_mention(self) -> None:
realm = get_realm("zulip")
gitlab_field = try_add_realm_default_custom_profile_field(realm, "gitlab")
hamlet = self.example_user("hamlet")
self.set_user_custom_profile_data(hamlet, [{"id": gitlab_field.id, "value": "Pritesh-30"}])
expected_topic_name = "deployment-webhook-test / production"
expected_message = f"@_**{hamlet.full_name}|{hamlet.id}** approved the [deployment](https://gitlab.com/pritesh-30-group/deployment-webhook-test/-/jobs/15664214926).\n``` quote\nApproval granted\n```"
self.check_webhook("deployment_hook__approval", expected_topic_name, expected_message)
def test_emoji_award_in_snippet(self) -> None:
expected_topic_name = "sample / snippet #4831194 Sample Snippet"
expected_message = "Varun Kolanu added the emoji :thumbsup:."
self.check_webhook("emoji_hook__award__snippet", expected_topic_name, expected_message)
def test_emoji_award_in_snippet_with_custom_topic(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
expected_message = "[[sample](https://gitlab.com/kolanuvarun/sample)] Varun Kolanu added the emoji :thumbsup: to [snippet #4831194](https://gitlab.com/kolanuvarun/sample/-/snippets/4831194)."
self.check_webhook(
"emoji_hook__award__snippet",
expected_topic_name,
expected_message,
)
def test_emoji_revoke_in_issue(self) -> None:
expected_topic_name = "sample / issue #1 Sample Issue"
expected_message = "Varun Kolanu removed the emoji :thumbsdown:."
self.check_webhook("emoji_hook__revoke__issue", expected_topic_name, expected_message)
def test_emoji_award_in_merge_request_without_merge_request_title(self) -> None:
expected_topic_name = "sample / MR #1"
expected_message = "Varun Kolanu added the emoji :thumbsup:."
self.url = self.build_webhook_url(use_merge_request_title="false")
self.check_webhook(
"emoji_hook__award__merge_request", expected_topic_name, expected_message
)
def test_emoji_award_in_merge_request_with_custom_topic(self) -> None:
expected_topic_name = "notifications"
expected_message = "[[sample](https://gitlab.com/kolanuvarun/sample)] Varun Kolanu added the emoji :thumbsup: to [MR #1](https://gitlab.com/kolanuvarun/sample/-/merge_requests/1)."
self.url = self.build_webhook_url(topic="notifications")
self.check_webhook(
"emoji_hook__award__merge_request",
expected_topic_name,
expected_message,
)
def test_emoji_revoke_in_merge_request_note(self) -> None:
expected_topic_name = "sample / MR #1 Edit README.md"
expected_message = "Varun Kolanu removed the emoji :heart: from [a comment](https://gitlab.com/kolanuvarun/sample/-/merge_requests/1#note_2431339003)."
self.check_webhook(
"emoji_hook__revoke__merge_request_note", expected_topic_name, expected_message
)
def test_emoji_award_in_design_note(self) -> None:
expected_topic_name = "sample / design Sample.png"
expected_message = "Varun Kolanu added the emoji :heart: to [a comment](https://gitlab.com/kolanuvarun/sample/-/issues/1/designs/Sample.png#note_2421525600)."
self.check_webhook("emoji_hook__award__design_note", expected_topic_name, expected_message)
def test_emoji_revoke_in_merge_request_note_with_custom_topic(self) -> None:
expected_topic_name = "notifications"
expected_message = "[[sample](https://gitlab.com/kolanuvarun/sample)] Varun Kolanu removed the emoji :heart: from [a comment](https://gitlab.com/kolanuvarun/sample/-/merge_requests/1#note_2431339003)."
self.url = self.build_webhook_url(topic="notifications")
self.check_webhook(
"emoji_hook__revoke__merge_request_note",
expected_topic_name,
expected_message,
)
def test_push_event_message_silent_mention(self) -> None:
realm = get_realm("zulip")
gitlab_field = try_add_realm_default_custom_profile_field(realm, "gitlab")
hamlet = self.example_user("hamlet")
self.set_user_custom_profile_data(
hamlet, [{"id": gitlab_field.id, "value": "tomaszkolek0"}]
)
expected_topic_name = "my-awesome-project / tomek"
expected_message = f"@_**{hamlet.full_name}|{hamlet.id}** [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek. Commits by Tomasz Kolek (2).\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))"
self.check_webhook("push_hook", expected_topic_name, expected_message)
def test_update_issue_event_message_silent_mention(self) -> None:
realm = get_realm("zulip")
gitlab_field = try_add_realm_default_custom_profile_field(realm, "gitlab")
hamlet = self.example_user("hamlet")
self.set_user_custom_profile_data(
hamlet, [{"id": gitlab_field.id, "value": "tomaszkolek0"}]
)
expected_topic_name = "my-awesome-project / issue #1 Issue title_new"
expected_message = f"@_**{hamlet.full_name}|{hamlet.id}** updated [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
self.check_webhook("issue_hook__issue_updated", expected_topic_name, expected_message)
def test_update_issue_event_message_silent_mention_multiple_matches(self) -> None:
realm = get_realm("zulip")
gitlab_field = try_add_realm_default_custom_profile_field(realm, "gitlab")
hamlet = self.example_user("hamlet")
self.set_user_custom_profile_data(
hamlet, [{"id": gitlab_field.id, "value": "tomaszkolek0"}]
)
cordelia = self.example_user("cordelia")
self.set_user_custom_profile_data(
cordelia, [{"id": gitlab_field.id, "value": "tomaszkolek0"}]
)
expected_topic_name = "my-awesome-project / issue #1 Issue title_new"
expected_message = "Tomasz Kolek updated [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)."
self.check_webhook("issue_hook__issue_updated", expected_topic_name, expected_message)