Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

webhooks/github: Support concise_edit_format for discussion events.

Niloth P4176217d5141
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py
index 14a11438f12..09d1affd52b 100644
--- a/zerver/lib/integrations.py
+++ b/zerver/lib/integrations.py
@@ -684,7 +684,7 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [
),
WebhookUrlOption(
name="concise_edit_format",
- label="Use concise edited issue and pull request notifications",
+ label="Use concise edited issue, pull request, and discussion notifications",
input_type="checkbox_enabled",
),
],
diff --git a/zerver/webhooks/github/doc.md b/zerver/webhooks/github/doc.md
index 727cee67af6..bfbdd0d6646 100644
--- a/zerver/webhooks/github/doc.md
+++ b/zerver/webhooks/github/doc.md
@@ -21,7 +21,8 @@ Get GitHub notifications in Zulip!
- Whether to exclude notifications from private repositories.
- Whether to include the repository name in the notifications.
- Whether to include emoji indicators in the notifications.
- - Whether to use a concise message format for edited issue and pull request notifications.
+ - Whether to use a concise message format for edited issue, pull request,
+ and discussion notifications.
1. On your repository's web page, go to **Settings**. Select **Webhooks**,
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py
index 2499e91dfb8..58640fae198 100644
--- a/zerver/webhooks/github/tests.py
+++ b/zerver/webhooks/github/tests.py
@@ -811,9 +811,14 @@ A temporary team so that I can get some webhook fixtures!
self.check_webhook("discussion__edited_title", expected_topic, expected_message)
def test_discussion_edited_body(self) -> None:
+ self.url = self.build_webhook_url(concise_edit_format="false")
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_edited_body_concise(self) -> None:
+ expected_message = "Niloth-p edited [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3)."
+ self.check_webhook("discussion__edited_body", TOPIC_DISCUSSION, expected_message)
+
def test_discussion_labeled(self) -> None:
expected_message = "Niloth-p added the enhancement label to [discussion #3](https://github.com/Niloth-p/webhook-tester/discussions/3)."
self.check_webhook("discussion__labeled", TOPIC_DISCUSSION, expected_message)
@@ -861,9 +866,14 @@ A temporary team so that I can get some webhook fixtures!
self.check_webhook("discussion_comment", expected_topic_name, expected_message)
def test_discussion_comment_edited_msg(self) -> None:
+ self.url = self.build_webhook_url(concise_edit_format="false")
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_discussion_comment_edited_msg_concise(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)."
+ self.check_webhook("discussion_comment__edited", TOPIC_DISCUSSION_COMMENT, expected_message)
+
def test_comment_edited_unchanged_skipped(self) -> None:
self.check_webhook(
fixture_name="issue_comment__edited__unchanged",
diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py
index a6acfc82904..14822ea95b6 100644
--- a/zerver/webhooks/github/view.py
+++ b/zerver/webhooks/github/view.py
@@ -446,30 +446,37 @@ class LazyContext(dict[str, str | int]):
def get_discussion_body(helper: Helper) -> str:
payload = helper.payload
- action = get_discussion_action(payload)
+ action = get_discussion_action(payload, helper.concise_edit_format)
DISCUSSION_TEMPLATE = DISCUSSION_TEMPLATES[action]
context = LazyContext(helper)
return DISCUSSION_TEMPLATE.format_map(context)
-def get_discussion_action(payload: WildValue) -> str:
+def get_discussion_action(payload: WildValue, concise_edit_format: bool) -> str:
action = payload["action"].tame(check_string)
if action in ("unlocked", "pinned", "unpinned", "reopened"):
action = "generic_action"
if action == "edited":
- edited_field = "body" if "body" in payload["changes"] else "title"
- action = f"edited_{edited_field}"
+ if "body" in payload["changes"]:
+ action = "generic_action" if concise_edit_format else "edited_body"
+ else:
+ action = "edited_title"
return action
def get_discussion_comment_body(helper: Helper) -> str:
payload = helper.payload
+ message = (
+ None
+ if payload["action"].tame(check_string) == "edited" and helper.concise_edit_format
+ else payload["comment"]["body"].tame(check_string)
+ )
return get_pull_request_event_message(
user_name=get_sender_name(helper),
action=get_comment_action(payload),
url=payload["discussion"]["html_url"].tame(check_string),
number=payload["discussion"]["number"].tame(check_int),
- message=payload["comment"]["body"].tame(check_string),
+ message=message,
title=payload["discussion"]["title"].tame(check_string) if helper.include_title else None,
type="discussion",
)