Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhook/github: Add emoji support for commit status events.
Pritesh Shettyf2cd3e3a2607
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.pyindex 8aa67a173e3..171658749c8 100644--- a/zerver/webhooks/github/tests.py+++ b/zerver/webhooks/github/tests.py@@ -402,23 +402,23 @@ class GitHubWebhookTest(WebhookTestCase):self.check_webhook("page_build__errored", TOPIC_REPO, expected_message)def test_status_msg(self) -> None:- expected_message = "[9049f1265b7](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to success."+ expected_message = ":check: [9049f1265b7](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to success."self.check_webhook("status__success", TOPIC_REPO, expected_message)def test_status_failure_msg(self) -> None:- expected_message = "[0d3d538167b](https://github.com/Pritesh-30/test-repo/commit/0d3d538167b1d22823353f5612141d18371dd42c) changed its status to failure."+ expected_message = ":warning: [0d3d538167b](https://github.com/Pritesh-30/test-repo/commit/0d3d538167b1d22823353f5612141d18371dd42c) changed its status to failure."self.check_webhook("status__failure", "test-repo", expected_message)def test_status_pending_msg(self) -> None:- expected_message = "[0d3d538167b](https://github.com/Pritesh-30/test-repo/commit/0d3d538167b1d22823353f5612141d18371dd42c) changed its status to pending."+ expected_message = ":time_ticking: [0d3d538167b](https://github.com/Pritesh-30/test-repo/commit/0d3d538167b1d22823353f5612141d18371dd42c) changed its status to pending."self.check_webhook("status__pending", "test-repo", expected_message)def test_status_error_msg(self) -> None:- expected_message = "[0d3d538167b](https://github.com/Pritesh-30/test-repo/commit/0d3d538167b1d22823353f5612141d18371dd42c) changed its status to error."+ expected_message = ":rotating_light: [0d3d538167b](https://github.com/Pritesh-30/test-repo/commit/0d3d538167b1d22823353f5612141d18371dd42c) changed its status to error."self.check_webhook("status__error", "test-repo", expected_message)def test_status_with_target_url_msg(self) -> None:- expected_message = "[9049f1265b7](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to [success](https://example.com/build/status)."+ expected_message = ":check: [9049f1265b7](https://github.com/baxterthehacker/public-repo/commit/9049f1265b7d61be4a8904a9a27120d2064dab3b) changed its status to [success](https://example.com/build/status)."self.check_webhook("status__with_target_url", TOPIC_REPO, expected_message)def test_pull_request_review_msg(self) -> None:diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.pyindex 80c4775d17d..17fdc37f002 100644--- a/zerver/webhooks/github/view.py+++ b/zerver/webhooks/github/view.py@@ -83,7 +83,7 @@ PR_CLOSE_ACTION_EMOJI = {"closed without merge": ":cross_mark:",}-DEPLOYMENT_STATUS_EMOJI = {+DEPLOYMENT_AND_COMMIT_STATUS_EMOJI = {"success": ":check:","failure": ":warning:","error": ":rotating_light:",@@ -294,7 +294,9 @@ def get_deployment_body(helper: Helper) -> str:def get_change_deployment_status_body(helper: Helper) -> str:payload = helper.payloadstate = payload["deployment_status"]["state"].tame(check_string)- emoji = DEPLOYMENT_STATUS_EMOJI.get(state, "") if helper.include_emoji_indicators else ""+ emoji = (+ DEPLOYMENT_AND_COMMIT_STATUS_EMOJI.get(state, "") if helper.include_emoji_indicators else ""+ )return f"{emoji} Deployment changed status to {state}.".strip()@@ -624,18 +626,22 @@ def get_page_build_body(helper: Helper) -> str:def get_status_body(helper: Helper) -> str:payload = helper.payload+ state = payload["state"].tame(check_string)if payload["target_url"]:- status = "[{}]({})".format(- payload["state"].tame(check_string),- payload["target_url"].tame(check_string),+ status = "[{state}]({target_url})".format(+ state=state,+ target_url=payload["target_url"].tame(check_string),)else:- status = payload["state"].tame(check_string)- return "[{}]({}) changed its status to {}.".format(- get_short_sha(payload["sha"].tame(check_string)),- payload["commit"]["html_url"].tame(check_string),- status,- )+ status = state+ return "{emoji} [{commit}]({url}) changed its status to {status}.".format(+ emoji=DEPLOYMENT_AND_COMMIT_STATUS_EMOJI.get(state, "")+ if helper.include_emoji_indicators+ else "",+ commit=get_short_sha(payload["sha"].tame(check_string)),+ url=payload["commit"]["html_url"].tame(check_string),+ status=status,+ ).strip()def get_locked_or_unlocked_pull_request_body(helper: Helper) -> str: