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: Add emojis for PR review states and close actions.

Pritesh Shetty131061302de0
diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py
index 13c125f0624..317f74db899 100644
--- a/zerver/lib/webhooks/git.py
+++ b/zerver/lib/webhooks/git.py
@@ -210,6 +210,7 @@ def get_pull_request_event_message(
title: str | None = None,
suffix: str | None = None,
include_topic_reference: bool = True,
+ emoji: str | None = None,
) -> str:
action_messages = {
"approval": "added their approval for",
@@ -274,6 +275,9 @@ def get_pull_request_event_message(
):
main_message = f"{main_message}{punctuation}"
+ if emoji:
+ main_message = f"{emoji} {main_message}"
+
if message:
fence = get_unused_fence(message)
main_message += "\n" + CONTENT_MESSAGE_TEMPLATE.format(message=message, fence=fence)
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py
index 60b9794aa28..720a7ea2f56 100644
--- a/zerver/webhooks/github/tests.py
+++ b/zerver/webhooks/github/tests.py
@@ -303,19 +303,17 @@ class GitHubWebhookTest(WebhookTestCase):
self.check_webhook("pull_request__synchronized", TOPIC_PR, expected_message)
def test_pull_request_closed_msg(self) -> None:
- expected_message = "baxterthehacker closed without merge [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)."
+ expected_message = ":cross_mark: baxterthehacker closed without merge [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)."
self.check_webhook("pull_request__closed", TOPIC_PR, expected_message)
def test_pull_request_closed_msg_with_custom_topic_in_url(self) -> None:
self.url = self.build_webhook_url(topic="notifications")
expected_topic_name = "notifications"
- expected_message = "baxterthehacker closed without merge [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1)."
+ expected_message = ":cross_mark: baxterthehacker closed without merge [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1)."
self.check_webhook("pull_request__closed", expected_topic_name, expected_message)
def test_pull_request_merged_msg(self) -> None:
- expected_message = (
- "baxterthehacker merged [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)."
- )
+ expected_message = ":check: baxterthehacker merged [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)."
self.check_webhook("pull_request__merged", TOPIC_PR, expected_message)
def test_pull_request_merged_msg_private_repository_skipped(self) -> None:
@@ -397,28 +395,28 @@ 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 = ":thumbs_up: 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 = ":thumbs_up: 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:
expected_topic_name = "groonga / PR #1581 grn_db_value_lock: unlock GRN_TYPE obj..."
- expected_message = "kou submitted [PR review](https://github.com/groonga/groonga/pull/1581#pullrequestreview-1483047907)."
+ expected_message = ":memo: kou submitted [PR review](https://github.com/groonga/groonga/pull/1581#pullrequestreview-1483047907)."
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 = ":speech_balloon: 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 = ":speech_balloon: 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:
diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py
index d27a0d4c821..ac0c6f990d7 100644
--- a/zerver/webhooks/github/view.py
+++ b/zerver/webhooks/github/view.py
@@ -70,6 +70,19 @@ CHECK_RUN_CONCLUSION_EMOJI = {
"stale": ":sleeping:",
}
+PR_REVIEW_STATE_EMOJI = {
+ "approved": ":thumbs_up:",
+ "changes_requested": ":repeat:",
+ "commented": ":memo:",
+}
+
+PR_REVIEW_COMMENT_EMOJI = ":speech_balloon:"
+
+PR_CLOSE_ACTION_EMOJI = {
+ "merged": ":check:",
+ "closed without merge": ":cross_mark:",
+}
+
class Helper:
def __init__(
@@ -153,6 +166,7 @@ def get_closed_pull_request_body(helper: Helper) -> str:
url=pull_request["html_url"].tame(check_string),
number=pull_request["number"].tame(check_int),
title=pull_request["title"].tame(check_string) if include_title else None,
+ emoji=PR_CLOSE_ACTION_EMOJI.get(action) if helper.include_emoji_indicators else None,
)
@@ -677,6 +691,9 @@ def get_pull_request_review_body(helper: Helper) -> str:
type="PR review",
title=title if include_title else None,
message=payload["review"]["body"].tame(check_none_or(check_string)),
+ emoji=PR_REVIEW_STATE_EMOJI.get(payload["review"]["state"].tame(check_string))
+ if helper.include_emoji_indicators
+ else None,
)
@@ -770,6 +787,7 @@ def get_pull_request_review_comment_body(helper: Helper) -> str:
message=message,
type="PR review comment",
title=title if include_title else None,
+ emoji=PR_REVIEW_COMMENT_EMOJI if helper.include_emoji_indicators else None,
)