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.

github: Fix quoting fences to work with arbitrary bodies.

Alex Vandiverd7b0ab33c9d8
diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py
index 4156a16cc93..13c125f0624 100644
--- a/zerver/lib/webhooks/git.py
+++ b/zerver/lib/webhooks/git.py
@@ -2,6 +2,8 @@ import string
from collections import defaultdict
from typing import Any
+from zerver.lib.markdown.fenced_code import get_unused_fence
+
TOPIC_WITH_BRANCH_TEMPLATE = "{repo} / {branch}"
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE = "{repo} / {type} #{id} {title}"
TOPIC_WITH_RELEASE_TEMPLATE = "{repo} / {tag} {title}"
@@ -59,7 +61,7 @@ PULL_REQUEST_OR_ISSUE_MESSAGE_TEMPLATE_WITHOUT_REFERENCE = "{user_name} {action}
PULL_REQUEST_OR_ISSUE_ASSIGNEE_INFO_TEMPLATE = "(assigned to {assignee})"
PULL_REQUEST_BRANCH_INFO_TEMPLATE = "from `{target}` to `{base}`"
-CONTENT_MESSAGE_TEMPLATE = "\n~~~ quote\n{message}\n~~~"
+CONTENT_MESSAGE_TEMPLATE = "\n{fence} quote\n{message}\n{fence}"
COMMITS_COMMENT_MESSAGE_TEMPLATE = "{user_name} {action} on [{sha}]({url})"
@@ -273,7 +275,8 @@ def get_pull_request_event_message(
main_message = f"{main_message}{punctuation}"
if message:
- main_message += "\n" + CONTENT_MESSAGE_TEMPLATE.format(message=message)
+ fence = get_unused_fence(message)
+ main_message += "\n" + CONTENT_MESSAGE_TEMPLATE.format(message=message, fence=fence)
return main_message.rstrip()
@@ -387,6 +390,7 @@ def get_commits_comment_action_message(
if message:
content += CONTENT_MESSAGE_TEMPLATE.format(
message=message,
+ fence=get_unused_fence(message),
)
return content
diff --git a/zerver/webhooks/azuredevops/tests.py b/zerver/webhooks/azuredevops/tests.py
index ff1cb5d3875..10a53ebf642 100644
--- a/zerver/webhooks/azuredevops/tests.py
+++ b/zerver/webhooks/azuredevops/tests.py
@@ -61,7 +61,7 @@ class AzuredevopsHookTests(WebhookTestCase):
def test_pull_request_opened(self) -> None:
expected_topic_name = "test-zulip / PR #1 Add PR request"
- expected_message = "Yuro Itaki created [PR #1 Add PR request](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/1) from `dev` to `main`:\n\n~~~ quote\nAdd PR request\n~~~"
+ expected_message = "Yuro Itaki created [PR #1 Add PR request](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/1) from `dev` to `main`:\n\n``` quote\nAdd PR request\n```"
self.check_webhook("code_pull_request__opened", expected_topic_name, expected_message)
def test_pull_request_opened_without_description(self) -> None:
@@ -88,5 +88,5 @@ class AzuredevopsHookTests(WebhookTestCase):
def test_pull_request_updated(self) -> None:
expected_topic_name = "test-zulip / PR #2 Raised 2nd PR!"
- expected_message = "Yuro Itaki updated [PR #2 Raised 2nd PR!](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/2)\n\n~~~ quote\nYuro Itaki updated the source branch of [pull request 2](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/2) (Raised 2nd PR!) in [test-zulip](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/)\r\nRaised 2nd PR!\r\n\n~~~"
+ expected_message = "Yuro Itaki updated [PR #2 Raised 2nd PR!](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/2)\n\n``` quote\nYuro Itaki updated the source branch of [pull request 2](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/2) (Raised 2nd PR!) in [test-zulip](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/)\r\nRaised 2nd PR!\r\n\n```"
self.check_webhook("code_pull_request__updated", expected_topic_name, expected_message)
diff --git a/zerver/webhooks/bitbucket/tests.py b/zerver/webhooks/bitbucket/tests.py
index 6b3a61b61db..5ba8fe46bae 100644
--- a/zerver/webhooks/bitbucket/tests.py
+++ b/zerver/webhooks/bitbucket/tests.py
@@ -92,7 +92,7 @@ class BitbucketHookTests(WebhookTestCase):
self.check_webhook("fork", TOPIC, expected_message)
def test_commit_comment_created_event(self) -> None:
- expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [32c4ea19aa3](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74):\n~~~ quote\nNice fix!\n~~~"
+ expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [32c4ea19aa3](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74):\n``` quote\nNice fix!\n```"
self.check_webhook("commit_comment_created", TOPIC, expected_message)
def test_commit_status_changed_event(self) -> None:
@@ -100,13 +100,13 @@ class BitbucketHookTests(WebhookTestCase):
self.check_webhook("commit_status_changed", TOPIC, expected_message)
def test_issue_created_event(self) -> None:
- expected_message = "Tomasz created [issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug) (assigned to Tomasz):\n\n~~~ quote\nSuch a bug\n~~~"
+ expected_message = "Tomasz created [issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug) (assigned to Tomasz):\n\n``` quote\nSuch a bug\n```"
self.check_webhook("issue_created", TOPIC_ISSUE_EVENTS, expected_message)
def test_issue_created_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "Tomasz created [issue #1 Bug](https://bitbucket.org/kolaszek/repository-name/issues/2/bug) (assigned to Tomasz):\n\n~~~ quote\nSuch a bug\n~~~"
+ expected_message = "Tomasz created [issue #1 Bug](https://bitbucket.org/kolaszek/repository-name/issues/2/bug) (assigned to Tomasz):\n\n``` quote\nSuch a bug\n```"
self.check_webhook("issue_created", expected_topic_name, expected_message)
def test_issue_updated_event(self) -> None:
@@ -124,7 +124,7 @@ class BitbucketHookTests(WebhookTestCase):
self.check_webhook("issue_commented", expected_topic_name, expected_message)
def test_pull_request_created_event(self) -> None:
- expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~"
+ expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n``` quote\ndescription\n```"
self.check_webhook(
"pull_request_created_or_updated",
TOPIC_PR_EVENTS,
@@ -133,7 +133,7 @@ class BitbucketHookTests(WebhookTestCase):
)
def test_pull_request_created_without_reviewer_username_event(self) -> None:
- expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~"
+ expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n``` quote\ndescription\n```"
self.check_webhook(
"pull_request_created_or_updated_without_username",
TOPIC_PR_EVENTS,
@@ -144,7 +144,7 @@ class BitbucketHookTests(WebhookTestCase):
def test_pull_request_created_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "Tomasz created [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~"
+ expected_message = "Tomasz created [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n``` quote\ndescription\n```"
self.check_webhook(
"pull_request_created_or_updated",
expected_topic_name,
@@ -153,7 +153,7 @@ class BitbucketHookTests(WebhookTestCase):
)
def test_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):\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,
@@ -209,7 +209,7 @@ class BitbucketHookTests(WebhookTestCase):
)
def test_pull_request_comment_created_event(self) -> None:
- expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~"
+ expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n``` quote\nComment1\n```"
self.check_webhook(
"pull_request_comment_action",
TOPIC_PR_EVENTS,
@@ -220,7 +220,7 @@ class BitbucketHookTests(WebhookTestCase):
def test_pull_request_comment_created_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~"
+ expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n``` quote\nComment1\n```"
self.check_webhook(
"pull_request_comment_action",
expected_topic_name,
@@ -229,7 +229,7 @@ class BitbucketHookTests(WebhookTestCase):
)
def test_pull_request_comment_updated_event(self) -> None:
- expected_message = "Tomasz updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~"
+ expected_message = "Tomasz updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n``` quote\nComment1\n```"
self.check_webhook(
"pull_request_comment_action",
TOPIC_PR_EVENTS,
@@ -240,7 +240,7 @@ class BitbucketHookTests(WebhookTestCase):
def test_pull_request_comment_updated_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "Tomasz updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~"
+ expected_message = "Tomasz updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n``` quote\nComment1\n```"
self.check_webhook(
"pull_request_comment_action",
expected_topic_name,
@@ -249,7 +249,7 @@ class BitbucketHookTests(WebhookTestCase):
)
def test_pull_request_comment_deleted_event(self) -> None:
- expected_message = "Tomasz deleted a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~"
+ expected_message = "Tomasz deleted a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n``` quote\nComment1\n```"
self.check_webhook(
"pull_request_comment_action",
TOPIC_PR_EVENTS,
diff --git a/zerver/webhooks/gitea/tests.py b/zerver/webhooks/gitea/tests.py
index 2dd81322650..7b8c8786d42 100644
--- a/zerver/webhooks/gitea/tests.py
+++ b/zerver/webhooks/gitea/tests.py
@@ -59,42 +59,42 @@ class GiteaHookTests(WebhookTestCase):
def test_issues_opened(self) -> None:
expected_topic_name = "test / issue #3 Test issue"
- expected_message = """kostekIV opened [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest body\n~~~"""
+ expected_message = """kostekIV opened [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n``` quote\nTest body\n```"""
self.check_webhook("issues__opened", expected_topic_name, expected_message)
def test_issues_edited(self) -> None:
expected_topic_name = "test / issue #3 Test issue 2"
- expected_message = """kostekIV edited [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~"""
+ expected_message = """kostekIV edited [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n``` quote\nTest body\n```"""
self.check_webhook("issues__edited", expected_topic_name, expected_message)
def test_issues_closed(self) -> None:
expected_topic_name = "test / issue #3 Test issue 2"
- expected_message = """kostekIV closed [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~"""
+ expected_message = """kostekIV closed [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n``` quote\nTest body\n```"""
self.check_webhook("issues__closed", expected_topic_name, expected_message)
def test_issues_assigned(self) -> None:
expected_topic_name = "test / issue #3 Test issue"
- expected_message = """kostekIV assigned kostekIV to [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~"""
+ expected_message = """kostekIV assigned kostekIV to [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n``` quote\nTest body\n```"""
self.check_webhook("issues__assigned", expected_topic_name, expected_message)
def test_issues_reopened(self) -> None:
expected_topic_name = "test / issue #3 Test issue 2"
- expected_message = """kostekIV reopened [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~"""
+ expected_message = """kostekIV reopened [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n``` quote\nTest body\n```"""
self.check_webhook("issues__reopened", expected_topic_name, expected_message)
def test_issue_comment_new(self) -> None:
expected_topic_name = "test / issue #3 Test issue"
- expected_message = """kostekIV [commented](https://try.gitea.io/kostekIV/test/issues/3#issuecomment-24400) on [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n~~~ quote\ntest comment\n~~~"""
+ expected_message = """kostekIV [commented](https://try.gitea.io/kostekIV/test/issues/3#issuecomment-24400) on [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n``` quote\ntest comment\n```"""
self.check_webhook("issue_comment__new", expected_topic_name, expected_message)
def test_issue_comment_in_pr(self) -> None:
expected_topic_name = "test / issue #1 dummy"
- expected_message = """kostekIV [commented](https://try.gitea.io/kostekIV/test/pulls/1/files#issuecomment-24399) on [issue #1](https://try.gitea.io/kostekIV/test/issues/1):\n\n~~~ quote\ntest comment\n~~~"""
+ expected_message = """kostekIV [commented](https://try.gitea.io/kostekIV/test/pulls/1/files#issuecomment-24399) on [issue #1](https://try.gitea.io/kostekIV/test/issues/1):\n\n``` quote\ntest comment\n```"""
self.check_webhook("issue_comment__in_pr", expected_topic_name, expected_message)
def test_issue_comment_edited(self) -> None:
expected_topic_name = "test / issue #3 Test issue 2"
- expected_message = """kostekIV edited a [comment](https://try.gitea.io/kostekIV/test/issues/3#issuecomment-24400) on [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n~~~ quote\nedit test comment\n~~~"""
+ expected_message = """kostekIV edited a [comment](https://try.gitea.io/kostekIV/test/issues/3#issuecomment-24400) on [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n``` quote\nedit test comment\n```"""
self.check_webhook("issue_comment__edited", expected_topic_name, expected_message)
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py
index ed563b6c53d..ecf988b095c 100644
--- a/zerver/webhooks/github/tests.py
+++ b/zerver/webhooks/github/tests.py
@@ -129,7 +129,7 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("push__multiple_committers", TOPIC_BRANCH, expected_message)
def test_commit_comment_msg(self) -> None:
- expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b#commitcomment-11056394) on [9049f1265b7](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b):\n~~~ quote\nThis is a really good change! :+1:\n~~~"
+ expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b#commitcomment-11056394) on [9049f1265b7](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b):\n``` quote\nThis is a really good change! :+1:\n```"
self.check_webhook("commit_comment", TOPIC_REPO, expected_message)
def test_create_msg(self) -> None:
@@ -154,42 +154,42 @@ class GitHubWebhookTest(WebhookTestCase):
def test_issues_edited_body(self) -> None:
expected_topic_name = "test-repo / issue #6 New Issue edited"
- expected_message = "Pritesh-30 edited [issue #6](https://github.com/Pritesh-30/test-repo/issues/6):\n\n~~~ quote\nThe body of the issue is edited.\n~~~"
+ expected_message = "Pritesh-30 edited [issue #6](https://github.com/Pritesh-30/test-repo/issues/6):\n\n``` quote\nThe body of the issue is edited.\n```"
self.check_webhook("issues__edited_body", expected_topic_name, expected_message)
def test_issues_edited_title(self) -> None:
long_title = "This is a very long issue title used to exceed Zulip's maximum topic length so that truncation logic is exercised when the issue title is edited via the GitHub webhook"
expected_topic_name = truncate_topic(f"test-repo / issue #6 {long_title}")
- expected_message = "Pritesh-30 edited [issue #6](https://github.com/Pritesh-30/test-repo/issues/6):\n\n~~~ quote\nThe body of the issue is edited.\n~~~"
+ expected_message = "Pritesh-30 edited [issue #6](https://github.com/Pritesh-30/test-repo/issues/6):\n\n``` quote\nThe body of the issue is edited.\n```"
self.check_webhook("issues__edited_title", expected_topic_name, expected_message)
def test_issue_comment_msg(self) -> None:
- expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~"
+ expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n``` quote\nYou are totally right! I'll get this fixed right away.\n```"
self.check_webhook("issue_comment", TOPIC_ISSUE, expected_message)
def test_issue_comment_deleted_msg(self) -> None:
expected_topic_name = "Scheduler / issue #5 This is a new issue"
- expected_message = "eeshangarg deleted a [comment](https://github.com/eeshangarg/Scheduler/issues/5#issuecomment-425164194) on [issue #5](https://github.com/eeshangarg/Scheduler/issues/5):\n\n~~~ quote\nThis is a comment on this new issue.\n~~~"
+ expected_message = "eeshangarg deleted a [comment](https://github.com/eeshangarg/Scheduler/issues/5#issuecomment-425164194) on [issue #5](https://github.com/eeshangarg/Scheduler/issues/5):\n\n``` quote\nThis is a comment on this new issue.\n```"
self.check_webhook("issue_comment__deleted", expected_topic_name, expected_message)
def test_issue_comment_msg_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~"
+ expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n``` quote\nYou are totally right! I'll get this fixed right away.\n```"
self.check_webhook("issue_comment", expected_topic_name, expected_message)
def test_issue_comment_pull_request_comment_msg(self) -> None:
- expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/public-repo/pull/1#issuecomment-1631445420) on [PR #1](https://github.com/sbansal1999/public-repo/pull/1):\n\n~~~ quote\nSome comment\n~~~"
+ expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/public-repo/pull/1#issuecomment-1631445420) on [PR #1](https://github.com/sbansal1999/public-repo/pull/1):\n\n``` quote\nSome comment\n```"
self.check_webhook("issue_comment__pull_request_comment", TOPIC_PR, expected_message)
def test_issue_msg(self) -> None:
- expected_message = "baxterthehacker opened [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nIt looks like you accidentally spelled 'commit' with two 't's.\n~~~"
+ expected_message = "baxterthehacker opened [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n``` quote\nIt looks like you accidentally spelled 'commit' with two 't's.\n```"
self.check_webhook("issues", TOPIC_ISSUE, expected_message)
def test_issue_msg_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "baxterthehacker opened [issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nIt looks like you accidentally spelled 'commit' with two 't's.\n~~~"
+ expected_message = "baxterthehacker opened [issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n``` quote\nIt looks like you accidentally spelled 'commit' with two 't's.\n```"
self.check_webhook("issues", expected_topic_name, expected_message)
def test_issue_assigned(self) -> None:
@@ -282,7 +282,7 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("member", TOPIC_REPO, expected_message)
def test_pull_request_opened_msg(self) -> None:
- expected_message = "baxterthehacker opened [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `baxterthehacker:changes` to `baxterthehacker:master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~"
+ expected_message = "baxterthehacker opened [PR #1](https://github.com/baxterthehacker/public-repo/pull/1) from `baxterthehacker:changes` to `baxterthehacker:master`:\n\n``` quote\nThis is a pretty simple change that we need to pull into master.\n```"
self.check_webhook("pull_request__opened", TOPIC_PR, expected_message)
def test_pull_request_opened_with_preassigned_assignee_msg(self) -> None:
@@ -295,7 +295,7 @@ class GitHubWebhookTest(WebhookTestCase):
def test_pull_request_opened_msg_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "baxterthehacker opened [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) from `baxterthehacker:changes` to `baxterthehacker:master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~"
+ expected_message = "baxterthehacker opened [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) from `baxterthehacker:changes` to `baxterthehacker:master`:\n\n``` quote\nThis is a pretty simple change that we need to pull into master.\n```"
self.check_webhook("pull_request__opened", expected_topic_name, expected_message)
def test_pull_request_synchronized_msg(self) -> None:
@@ -385,7 +385,7 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("page_build", TOPIC_REPO, expected_message)
def test_page_build_errored_msg(self) -> None:
- expected_message = "GitHub Pages build, triggered by baxterthehacker, has failed: \n~~~ quote\nSomething went wrong.\n~~~."
+ expected_message = "GitHub Pages build, triggered by baxterthehacker, has failed: \n``` quote\nSomething went wrong.\n```."
self.check_webhook("page_build__errored", TOPIC_REPO, expected_message)
def test_status_msg(self) -> None:
@@ -397,13 +397,13 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("status__with_target_url", TOPIC_REPO, expected_message)
def test_pull_request_review_msg(self) -> None:
- expected_message = "baxterthehacker submitted [PR review](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884):\n\n~~~ quote\nLooks great!\n~~~"
+ expected_message = "baxterthehacker submitted [PR review](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884):\n\n``` quote\nLooks great!\n```"
self.check_webhook("pull_request_review", TOPIC_PR, expected_message)
def test_pull_request_review_msg_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "baxterthehacker submitted [PR review for #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884):\n\n~~~ quote\nLooks great!\n~~~"
+ expected_message = "baxterthehacker submitted [PR review for #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884):\n\n``` quote\nLooks great!\n```"
self.check_webhook("pull_request_review", expected_topic_name, expected_message)
def test_pull_request_review_msg_with_empty_body(self) -> None:
@@ -412,13 +412,13 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("pull_request_review__empty_body", expected_topic_name, expected_message)
def test_pull_request_review_comment_msg(self) -> None:
- expected_message = "baxterthehacker created [PR review comment](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~"
+ expected_message = "baxterthehacker created [PR review comment](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n``` quote\nMaybe you should use more emojji on this line.\n```"
self.check_webhook("pull_request_review_comment", TOPIC_PR, expected_message)
def test_pull_request_review_comment_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "baxterthehacker created [PR review comment on #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~"
+ expected_message = "baxterthehacker created [PR review comment on #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n``` quote\nMaybe you should use more emojji on this line.\n```"
self.check_webhook("pull_request_review_comment", expected_topic_name, expected_message)
def test_pull_request_locked(self) -> None:
@@ -450,7 +450,7 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("pull_request__edited", TOPIC_PR, expected_message)
def test_pull_request_edited_with_body_change(self) -> None:
- expected_message = "cozyrohan edited [PR #1](https://github.com/cozyrohan/public-repo/pull/1):\n\n~~~ quote\nPR EDITED\n~~~"
+ expected_message = "cozyrohan edited [PR #1](https://github.com/cozyrohan/public-repo/pull/1):\n\n``` quote\nPR EDITED\n```"
self.check_webhook("pull_request__edited_with_body_change", TOPIC_PR, expected_message)
def test_pull_request_synchronized_with_body(self) -> None:
@@ -571,9 +571,9 @@ Check [randscape](http://github.com/github/hello-world/runs/4) completed (succes
expected_topic_name = "team Testing"
expected_message = """\
Hypro999 changed the team description to:
-\n~~~ quote
+\n``` quote
A temporary team so that I can get some webhook fixtures!
-~~~"""
+```"""
self.check_webhook("team__edited_description", expected_topic_name, expected_message)
def test_team_edited_name(self) -> None:
@@ -702,7 +702,7 @@ A temporary team so that I can get some webhook fixtures!
self.assertTrue(stack_info)
def test_discussion_answered(self) -> None:
- expected_message = "Niloth-p marked [comment #11460065](https://github.com/Niloth-p/webhook-tester/discussions/5#discussioncomment-11460065) as the answer:\n\n~~~ quote\nIf you're looking for a detailed explanation of the project structure, I'd recommend checking out our CONTRIBUTING.md file. It includes a breakdown of the different directories and files, as well as some guidelines for contributing to the project.\n~~~"
+ expected_message = "Niloth-p marked [comment #11460065](https://github.com/Niloth-p/webhook-tester/discussions/5#discussioncomment-11460065) as the answer:\n\n``` quote\nIf you're looking for a detailed explanation of the project structure, I'd recommend checking out our CONTRIBUTING.md file. It includes a breakdown of the different directories and files, as well as some guidelines for contributing to the project.\n```"
self.check_webhook("discussion__answered", TOPIC_DISCUSSION_ANSWERS, expected_message)
def test_discussion_category_changed(self) -> None:
@@ -716,7 +716,7 @@ A temporary team so that I can get some webhook fixtures!
self.check_webhook("discussion__category_changed", expected_topic_name, expected_message)
def test_discussion_created(self) -> None:
- expected_message = "Niloth-p created [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3) in General:\n\n~~~ quote\n### Tips for Writing Clear and Concise Commit Messages\nWriting good commit messages is an art, but it's also an important part of maintaining a clear and understandable project history. What are some tips and tricks you've learned for writing clear and concise commit messages? Do you have any favorite templates or formats?\n~~~"
+ expected_message = "Niloth-p created [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3) in General:\n\n``` quote\n### Tips for Writing Clear and Concise Commit Messages\nWriting good commit messages is an art, but it's also an important part of maintaining a clear and understandable project history. What are some tips and tricks you've learned for writing clear and concise commit messages? Do you have any favorite templates or formats?\n```"
self.check_webhook("discussion__created", TOPIC_DISCUSSION, expected_message)
def test_discussion_closed(self) -> None:
@@ -729,11 +729,11 @@ A temporary team so that I can get some webhook fixtures!
def test_discussion_edited_title(self) -> None:
expected_topic = "webhook-tester discussion #3: Tips for Writing Good Commi..."
- expected_message = "Niloth-p edited the title of [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3):\n\n~~~ quote\n### Tips for Writing Good Commit Messages\n~~~"
+ expected_message = "Niloth-p edited the title of [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3):\n\n``` quote\n### Tips for Writing Good Commit Messages\n```"
self.check_webhook("discussion__edited_title", expected_topic, expected_message)
def test_discussion_edited_body(self) -> None:
- expected_message = "Niloth-p edited [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3):\n\n~~~ quote\nWriting good commit messages is an art, but it's also an important part of maintaining a clear and understandable project history. What are some tips and tricks you've learned for writing clear and concise commit messages? Do you have any favorite templates or formats?\r\nAny advice would be greatly appreciated!\n~~~"
+ expected_message = "Niloth-p edited [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3):\n\n``` quote\nWriting good commit messages is an art, but it's also an important part of maintaining a clear and understandable project history. What are some tips and tricks you've learned for writing clear and concise commit messages? Do you have any favorite templates or formats?\r\nAny advice would be greatly appreciated!\n```"
self.check_webhook("discussion__edited_body", TOPIC_DISCUSSION, expected_message)
def test_discussion_labeled(self) -> None:
@@ -773,17 +773,17 @@ A temporary team so that I can get some webhook fixtures!
self.check_webhook("discussion__unanswered", TOPIC_DISCUSSION_ANSWERS, expected_message)
def test_discussion_comment_msg(self) -> None:
- expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n~~~ quote\nsome random comment\n~~~"
+ expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n``` quote\nsome random comment\n```"
self.check_webhook("discussion_comment", TOPIC_DISCUSSION_COMMENT, expected_message)
def test_discussion_comment_msg_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20 Lets discuss](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n~~~ quote\nsome random comment\n~~~"
+ expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20 Lets discuss](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n``` quote\nsome random comment\n```"
self.check_webhook("discussion_comment", expected_topic_name, expected_message)
def test_discussion_comment_edited_msg(self) -> None:
- expected_message = "sbansal1999 edited a [comment](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n~~~ quote\nsome random comment edited\n~~~"
+ expected_message = "sbansal1999 edited a [comment](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n``` quote\nsome random comment edited\n```"
self.check_webhook("discussion_comment__edited", TOPIC_DISCUSSION_COMMENT, expected_message)
def test_comment_edited_unchanged_skipped(self) -> None:
@@ -804,7 +804,7 @@ A temporary team so that I can get some webhook fixtures!
self.set_user_custom_profile_data(
hamlet, [{"id": github_field.id, "value": "baxterthehacker"}]
)
- expected_message = f"@_**{hamlet.full_name}|{hamlet.id}** [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~"
+ expected_message = f"@_**{hamlet.full_name}|{hamlet.id}** [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n``` quote\nYou are totally right! I'll get this fixed right away.\n```"
self.check_webhook("issue_comment", TOPIC_ISSUE, expected_message)
def test_issue_comment_silent_mention_with_multiple_matches(self) -> None:
@@ -821,7 +821,7 @@ A temporary team so that I can get some webhook fixtures!
self.set_user_custom_profile_data(
cordelia, [{"id": github_field.id, "value": "baxterthehacker"}]
)
- expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~"
+ expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2](https://github.com/baxterthehacker/public-repo/issues/2):\n\n``` quote\nYou are totally right! I'll get this fixed right away.\n```"
self.check_webhook("issue_comment", TOPIC_ISSUE, expected_message)
diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py
index 6b3ed57f09b..5a0b150e591 100644
--- a/zerver/webhooks/github/view.py
+++ b/zerver/webhooks/github/view.py
@@ -9,6 +9,7 @@ from typing_extensions import override
from zerver.decorator import log_unsupported_webhook_event, webhook_view
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
from zerver.lib.external_accounts import DEFAULT_EXTERNAL_ACCOUNTS
+from zerver.lib.markdown.fenced_code import get_unused_fence
from zerver.lib.mention import silent_mention_syntax_for_user
from zerver.lib.partial import partial
from zerver.lib.response import json_success
@@ -43,7 +44,7 @@ fixture_to_headers = default_fixture_to_headers("HTTP_X_GITHUB_EVENT")
TOPIC_FOR_DISCUSSION = "{repo} discussion #{number}: {title}"
DISCUSSION_TEMPLATES = {
- "created": "{sender} created [discussion #{discussion_number}]({url}) in {category}:\n\n~~~ quote\n### {title}\n{body}\n~~~",
+ "created": "{sender} created [discussion #{discussion_number}]({url}) in {category}:\n\n{body_fence} quote\n### {title}\n{body}\n{body_fence}",
"generic_action": "{sender} {action} [discussion #{discussion_number}{configured_title}]({url}).",
"deleted": "{sender} {action} discussion #{discussion_number}{configured_title}.",
"closed": "{sender} {action} [discussion #{discussion_number}{configured_title}]({url}) as {closed_reason}.",
@@ -52,10 +53,10 @@ DISCUSSION_TEMPLATES = {
"unlabeled": "{sender} removed the {label} label from [discussion #{discussion_number}{configured_title}]({url}).",
"category_changed": "{sender} changed the category of [discussion #{discussion_number}{configured_title}]({url}) from {old_category} to {category}.",
"transferred": "{sender} {action} discussion #{discussion_number}{configured_title} from {repository_name} to {new_repository_name} as [discussion #{new_discussion_number}]({url}).",
- "answered": "{sender} marked [comment #{comment_id}]({answer_url}) as the answer:\n\n~~~ quote\n{answer_body}\n~~~",
+ "answered": "{sender} marked [comment #{comment_id}]({answer_url}) as the answer:\n\n{answer_body_fence} quote\n{answer_body}\n{answer_body_fence}",
"unanswered": "{sender} marked [comment #{comment_id}]({answer_url}) as not the answer.",
- "edited_title": "{sender} edited the title of [discussion #{discussion_number}{configured_title}]({url}):\n\n~~~ quote\n### {title}\n~~~",
- "edited_body": "{sender} edited [discussion #{discussion_number}{configured_title}]({url}):\n\n~~~ quote\n{body}\n~~~",
+ "edited_title": "{sender} edited the title of [discussion #{discussion_number}{configured_title}]({url}):\n\n``` quote\n### {title}\n```",
+ "edited_body": "{sender} edited [discussion #{discussion_number}{configured_title}]({url}):\n\n{body_fence} quote\n{body}\n{body_fence}",
}
@@ -350,6 +351,7 @@ class LazyContext(dict[str, str | int]):
"category": lambda: self.payload["discussion"]["category"]["name"].tame(check_string),
"title": lambda: self.payload["discussion"]["title"].tame(check_string),
"body": lambda: self.payload["discussion"]["body"].tame(check_string),
+ "body_fence": lambda: get_unused_fence(str(self.template_values["body"]())),
"repository_name": lambda: self.payload["repository"]["name"].tame(check_string),
"new_repository_name": lambda: self.payload["changes"]["new_repository"]["name"].tame(
check_string
@@ -385,6 +387,9 @@ class LazyContext(dict[str, str | int]):
"answer_body": lambda: self.payload[self.template_values["answer_field"]()][
"body"
].tame(check_string),
+ "answer_body_fence": lambda: get_unused_fence(
+ str(self.template_values["answer_body"]())
+ ),
"comment_id": lambda: self.payload[self.template_values["answer_field"]()]["id"].tame(
check_int
),
@@ -471,13 +476,17 @@ def get_repository_advisory_body(helper: Helper) -> str:
payload = helper.payload
action = payload["action"].tame(check_string)
if action == "reported":
- return "{} reported [{}]({}) in {}: {}\n\n```quote\n{}\n```".format(
+ description = payload["repository_advisory"]["description"].tame(check_string)
+ fence = get_unused_fence(description)
+ return "{} reported [{}]({}) in {}: {}\n\n{}quote\n{}\n{}".format(
get_sender_name(helper),
payload["repository_advisory"]["ghsa_id"].tame(check_string),
payload["repository_advisory"]["html_url"].tame(check_string),
get_repository_full_name(payload),
payload["repository_advisory"]["summary"].tame(check_string),
- payload["repository_advisory"]["description"].tame(check_string),
+ fence,
+ description,
+ fence,
)
else:
return "{} published [{}]({})".format(
@@ -512,7 +521,10 @@ def get_team_body(helper: Helper) -> str:
if "description" in changes:
actor = get_sender_name(helper)
new_description = payload["team"]["description"].tame(check_string)
- return f"{actor} changed the team description to:\n\n~~~ quote\n{new_description}\n~~~"
+ fence = get_unused_fence(new_description)
+ return (
+ f"{actor} changed the team description to:\n\n{fence} quote\n{new_description}\n{fence}"
+ )
if "name" in changes:
original_name = changes["name"]["from"].tame(check_string)
new_name = payload["team"]["name"].tame(check_string)
@@ -562,8 +574,12 @@ def get_page_build_body(helper: Helper) -> str:
action = actions.get(status, f"is {status}")
if build["error"]["message"]:
+ message = build["error"]["message"].tame(check_string)
action = action.format(
- CONTENT_MESSAGE_TEMPLATE.format(message=build["error"]["message"].tame(check_string)),
+ CONTENT_MESSAGE_TEMPLATE.format(
+ message=message,
+ fence=get_unused_fence(message),
+ ),
)
return "GitHub Pages build, triggered by {}, {}.".format(
diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py
index 322277c25ab..501d55e0d17 100644
--- a/zerver/webhooks/gitlab/tests.py
+++ b/zerver/webhooks/gitlab/tests.py
@@ -90,7 +90,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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
@@ -98,7 +98,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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(
"issue_hook__confidential_issue_created_without_assignee",
@@ -109,7 +109,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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
@@ -117,7 +117,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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
@@ -125,7 +125,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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
@@ -133,7 +133,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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
@@ -141,7 +141,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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(
"issue_hook__confidential_issue_created_with_assignee",
@@ -151,7 +151,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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",
@@ -161,7 +161,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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(
"issue_hook__confidential_issue_created_with_hidden_comment_in_description",
@@ -227,19 +227,19 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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~~~"
+ 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~~~"
+ 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)
@@ -247,64 +247,64 @@ 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_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~~~"
+ 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~~~"
+ 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~~~"
+ 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~~~"
+ 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("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_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~~~"
+ 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~~~"
+ 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~~~"
+ 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~~~"
+ 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~~~"
+ 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~~~"
+ 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",
@@ -315,7 +315,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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",
@@ -325,7 +325,7 @@ class GitlabHookTests(WebhookTestCase):
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~~~"
+ 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,
@@ -337,9 +337,9 @@ class GitlabHookTests(WebhookTestCase):
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
+``` quote
A trivial change that should probably be ignored.
-~~~
+```
""".strip()
self.check_webhook(
"merge_request_hook__merge_request_created_with_multiple_assignees",
@@ -406,7 +406,7 @@ A trivial change that should probably be ignored.
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~~~"
+ 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
)
@@ -607,7 +607,7 @@ A trivial change that should probably be ignored.
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~~~"
+ 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",
@@ -618,7 +618,7 @@ A trivial change that should probably be ignored.
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~~~"
+ 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",
@@ -628,7 +628,7 @@ A trivial change that should probably be ignored.
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~~~"
+ 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,
@@ -670,20 +670,20 @@ A trivial change that should probably be ignored.
def test_release_created_event_message(self) -> None:
expected_topic_name = "release-webhook-example"
- expected_message = "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~~~"
+ expected_message = "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__create", expected_topic_name, expected_message)
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~~~"
+ 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__create", expected_topic_name, expected_message)
def test_release_update_event_message(self) -> None:
expected_topic_name = "release-webhook-example"
- expected_message = "Release [v1.1](https://example.com/gitlab-org/release-webhook-example/-/releases/v1.1) for tag v1.1 was updated.\n~~~ quote\n## v1.1 (2024-09-06)\n\n- Feature added\n~~~"
+ expected_message = "Release [v1.1](https://example.com/gitlab-org/release-webhook-example/-/releases/v1.1) for tag v1.1 was updated.\n``` quote\n## v1.1 (2024-09-06)\n\n- Feature added\n```"
self.check_webhook("release_hook__update", expected_topic_name, expected_message)
diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py
index 13f2edd38d1..c363dae79e6 100644
--- a/zerver/webhooks/gitlab/view.py
+++ b/zerver/webhooks/gitlab/view.py
@@ -7,6 +7,7 @@ from pydantic import Json
from zerver.decorator import webhook_view
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
+from zerver.lib.markdown.fenced_code import get_unused_fence
from zerver.lib.partial import partial
from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
@@ -293,7 +294,10 @@ def get_commented_design_event_body(payload: WildValue, include_title: bool) ->
comment_url, design_url, design_name = parse_design_comment(comment, repository_url)
action = f"[commented]({comment_url})"
- content_message = CONTENT_MESSAGE_TEMPLATE.format(message=comment["note"].tame(check_string))
+ message = comment["note"].tame(check_string)
+ content_message = CONTENT_MESSAGE_TEMPLATE.format(
+ message=message, fence=get_unused_fence(message)
+ )
message_template = (
DESIGN_COMMENT_MESSAGE_TEMPLATE
if include_title
@@ -422,7 +426,9 @@ def get_release_event_body(payload: WildValue, include_title: bool) -> str:
if "description" in payload:
description = payload["description"].tame(check_string)
- body += CONTENT_MESSAGE_TEMPLATE.format(message=description)
+ body += CONTENT_MESSAGE_TEMPLATE.format(
+ message=description, fence=get_unused_fence(description)
+ )
return body
diff --git a/zerver/webhooks/gogs/tests.py b/zerver/webhooks/gogs/tests.py
index 5fbb4c436aa..ee2d098e753 100644
--- a/zerver/webhooks/gogs/tests.py
+++ b/zerver/webhooks/gogs/tests.py
@@ -100,37 +100,37 @@ class GogsHookTests(WebhookTestCase):
def test_issues_opened(self) -> None:
expected_topic_name = "test / issue #3 New test issue"
- expected_message = """kostekIV opened [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest\n~~~"""
+ expected_message = """kostekIV opened [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n``` quote\nTest\n```"""
self.check_webhook("issues__opened", expected_topic_name, expected_message)
def test_issues_reopened(self) -> None:
expected_topic_name = "test / issue #3 New test issue"
- expected_message = """kostekIV reopened [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest\n~~~"""
+ expected_message = """kostekIV reopened [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n``` quote\nTest\n```"""
self.check_webhook("issues__reopened", expected_topic_name, expected_message)
def test_issues_edited(self) -> None:
expected_topic_name = "test / issue #3 New test issue"
- expected_message = """kostekIV edited [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest edit\n~~~"""
+ expected_message = """kostekIV edited [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n``` quote\nTest edit\n```"""
self.check_webhook("issues__edited", expected_topic_name, expected_message)
def test_issues_assignee(self) -> None:
expected_topic_name = "test / issue #3 New test issue"
- expected_message = """kostekIV assigned kostekIV to [issue #3](https://try.gogs.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest\n~~~"""
+ expected_message = """kostekIV assigned kostekIV to [issue #3](https://try.gogs.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n``` quote\nTest\n```"""
self.check_webhook("issues__assigned", expected_topic_name, expected_message)
def test_issues_closed(self) -> None:
expected_topic_name = "test / issue #3 New test issue"
- expected_message = """kostekIV closed [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nClosed #3\n~~~"""
+ expected_message = """kostekIV closed [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n``` quote\nClosed #3\n```"""
self.check_webhook("issues__closed", expected_topic_name, expected_message)
def test_issue_comment_new(self) -> None:
expected_topic_name = "test / issue #3 New test issue"
- expected_message = """kostekIV [commented](https://try.gogs.io/kostekIV/test/issues/3#issuecomment-3635) on [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest comment\n~~~"""
+ expected_message = """kostekIV [commented](https://try.gogs.io/kostekIV/test/issues/3#issuecomment-3635) on [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n``` quote\nTest comment\n```"""
self.check_webhook("issue_comment__new", expected_topic_name, expected_message)
def test_issue_comment_edited(self) -> None:
expected_topic_name = "test / issue #3 New test issue"
- expected_message = """kostekIV edited a [comment](https://try.gogs.io/kostekIV/test/issues/3#issuecomment-3634) on [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nedit comment\n~~~"""
+ expected_message = """kostekIV edited a [comment](https://try.gogs.io/kostekIV/test/issues/3#issuecomment-3634) on [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n``` quote\nedit comment\n```"""
self.check_webhook("issue_comment__edited", expected_topic_name, expected_message)
def test_release_published(self) -> None: