From 297185cc12afe6f729309b9fcec37c8f478cd778 Mon Sep 17 00:00:00 2001 From: cestrell Date: Mon, 11 May 2020 20:39:57 -0400 Subject: [PATCH] integrations: Use new function in Github releases. Use get_release_event_message from webhooks/git.py to format release events using the newly implemented release message template. Tweaked by tabbott to handle name=None. Builds on #14746. Proposed in #14934. --- zerver/webhooks/github/tests.py | 2 +- zerver/webhooks/github/view.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py index 19364050a8..8ccbda5e7d 100644 --- a/zerver/webhooks/github/tests.py +++ b/zerver/webhooks/github/tests.py @@ -206,7 +206,7 @@ class GithubWebhookTest(WebhookTestCase): self.send_and_test_stream_message('team_add', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message) def test_release_msg(self) -> None: - expected_message = "baxterthehacker published [release for tag 0.0.1](https://github.com/baxterthehacker/public-repo/releases/tag/0.0.1)." + expected_message = "baxterthehacker published release [0.0.1](https://github.com/baxterthehacker/public-repo/releases/tag/0.0.1) for tag 0.0.1." self.send_and_test_stream_message('release', self.EXPECTED_TOPIC_REPO_EVENTS, expected_message) def test_page_build_msg(self) -> None: diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index 35af6911c5..77bb1a3580 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -15,7 +15,8 @@ from zerver.lib.webhooks.git import CONTENT_MESSAGE_TEMPLATE, \ TOPIC_WITH_BRANCH_TEMPLATE, TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ get_commits_comment_action_message, get_issue_event_message, \ get_pull_request_event_message, get_push_commits_event_message, \ - get_push_tag_event_message, get_setup_webhook_message + get_push_tag_event_message, get_setup_webhook_message, \ + get_release_event_message from zerver.models import UserProfile fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITHUB_EVENT") @@ -235,12 +236,16 @@ def get_add_team_body(payload: Dict[str, Any]) -> str: ) def get_release_body(payload: Dict[str, Any]) -> str: - return "{} {} [release for tag {}]({}).".format( - get_sender_name(payload), - payload['action'], - payload['release']['tag_name'], - payload['release']['html_url'], - ) + data = { + 'user_name': get_sender_name(payload), + 'action': payload['action'], + 'tagname': payload['release']['tag_name'], + # Not every GitHub release has a "name" set; if not there, use the tag name. + 'release_name': payload['release']['name'] or payload['release']['tag_name'], + 'url': payload['release']['html_url'] + } + + return get_release_event_message(**data) def get_page_build_body(payload: Dict[str, Any]) -> str: build = payload['build']