mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
webhooks/github: Include discussion ID in messages.
We add discussion id and url in the comments and highlighted title to the body of disscussion message to make it more meaningful and accessible. Fixes #19938.
This commit is contained in:
@@ -486,9 +486,9 @@ A temporary team so that I can get some webhook fixtures!
|
|||||||
self.assertTrue(stack_info)
|
self.assertTrue(stack_info)
|
||||||
|
|
||||||
def test_discussion_msg(self) -> None:
|
def test_discussion_msg(self) -> None:
|
||||||
expected_message = "Codertocat started a new discussion [Welcome to discussions!](https://github.com/baxterthehacker/public-repo/discussions/90) in General:\n```quote\nWe're glad to have you here!\n```"
|
expected_message = "Codertocat created [discussion #90](https://github.com/baxterthehacker/public-repo/discussions/90) in General:\n```quote\n### Welcome to discussions!\nWe're glad to have you here!\n```"
|
||||||
self.check_webhook("discussion", TOPIC_DISCUSSION, expected_message)
|
self.check_webhook("discussion", TOPIC_DISCUSSION, expected_message)
|
||||||
|
|
||||||
def test_discussion_comment_msg(self) -> None:
|
def test_discussion_comment_msg(self) -> None:
|
||||||
expected_message = "Codertocat [commented](https://github.com/baxterthehacker/public-repo/discussions/90#discussioncomment-544078) on [discussion](https://github.com/baxterthehacker/public-repo/discussions/90):\n```quote\nI have so many questions to ask you!\n```"
|
expected_message = "Codertocat [commented](https://github.com/baxterthehacker/public-repo/discussions/90#discussioncomment-544078) on [discussion #90](https://github.com/baxterthehacker/public-repo/discussions/90):\n```quote\nI have so many questions to ask you!\n```"
|
||||||
self.check_webhook("discussion_comment", TOPIC_DISCUSSION, expected_message)
|
self.check_webhook("discussion_comment", TOPIC_DISCUSSION, expected_message)
|
||||||
|
|||||||
@@ -30,12 +30,8 @@ from zerver.models import UserProfile
|
|||||||
fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITHUB_EVENT")
|
fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITHUB_EVENT")
|
||||||
|
|
||||||
TOPIC_FOR_DISCUSSION = "{repo} discussion #{number}: {title}"
|
TOPIC_FOR_DISCUSSION = "{repo} discussion #{number}: {title}"
|
||||||
DISCUSSION_TEMPLATE = (
|
DISCUSSION_TEMPLATE = "{author} created [discussion #{discussion_id}]({url}) in {category}:\n```quote\n### {title}\n{body}\n```"
|
||||||
"{author} started a new discussion [{title}]({url}) in {category}:\n```quote\n{body}\n```"
|
DISCUSSION_COMMENT_TEMPLATE = "{author} [commented]({comment_url}) on [discussion #{discussion_id}]({discussion_url}):\n```quote\n{body}\n```"
|
||||||
)
|
|
||||||
DISCUSSION_COMMENT_TEMPLATE = (
|
|
||||||
"{author} [commented]({comment_url}) on [discussion]({discussion_url}):\n```quote\n{body}\n```"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Helper:
|
class Helper:
|
||||||
@@ -266,10 +262,11 @@ def get_discussion_body(helper: Helper) -> str:
|
|||||||
payload = helper.payload
|
payload = helper.payload
|
||||||
return DISCUSSION_TEMPLATE.format(
|
return DISCUSSION_TEMPLATE.format(
|
||||||
author=get_sender_name(payload),
|
author=get_sender_name(payload),
|
||||||
title=payload["discussion"]["title"],
|
|
||||||
url=payload["discussion"]["html_url"],
|
url=payload["discussion"]["html_url"],
|
||||||
body=payload["discussion"]["body"],
|
body=payload["discussion"]["body"],
|
||||||
category=payload["discussion"]["category"]["name"],
|
category=payload["discussion"]["category"]["name"],
|
||||||
|
discussion_id=payload["discussion"]["number"],
|
||||||
|
title=payload["discussion"]["title"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -280,6 +277,7 @@ def get_discussion_comment_body(helper: Helper) -> str:
|
|||||||
body=payload["comment"]["body"],
|
body=payload["comment"]["body"],
|
||||||
discussion_url=payload["discussion"]["html_url"],
|
discussion_url=payload["discussion"]["html_url"],
|
||||||
comment_url=payload["comment"]["html_url"],
|
comment_url=payload["comment"]["html_url"],
|
||||||
|
discussion_id=payload["discussion"]["number"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user