From f6e17fa972dbd8792bc0d569e112d4f289e0f81c Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Wed, 22 Nov 2023 04:17:21 +0100 Subject: [PATCH] integrations: Reformat Github issue assigned message body. Instead of adding the assignee to the end of the message body, we update the message body where the verb is so that the link formatting at the end of the message is not broken, for example: "user_a assigned user_b to [issue #XXX title text is here](link)." Also updates the issue title in the test fixture so that it tests that only the first instance of "assigned" or "unassigned" in the issue title is updated for the assignee text. Also adds punctuation to the issue title in the test fixture to test the expected behavior for titles that end in a value from `string.punctuation`. --- zerver/webhooks/github/fixtures/issues__assigned.json | 2 +- zerver/webhooks/github/tests.py | 6 +++--- zerver/webhooks/github/view.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zerver/webhooks/github/fixtures/issues__assigned.json b/zerver/webhooks/github/fixtures/issues__assigned.json index c4f7349da5..89af7907f2 100644 --- a/zerver/webhooks/github/fixtures/issues__assigned.json +++ b/zerver/webhooks/github/fixtures/issues__assigned.json @@ -10,7 +10,7 @@ "id": 1651035101, "node_id": "I_kwDOJRp_V85iaMvd", "number": 7, - "title": "Sample Issue testing something", + "title": "Testing when issue assigned!", "user": { "login": "sbansal1999", "id": 35286603, diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py index c4364836c2..83df42c6c3 100644 --- a/zerver/webhooks/github/tests.py +++ b/zerver/webhooks/github/tests.py @@ -160,14 +160,14 @@ class GitHubWebhookTest(WebhookTestCase): self.check_webhook("issues", expected_topic, expected_message) def test_issue_assigned(self) -> None: - expected_message = "sbansal1999 assigned [issue #7](https://github.com/sbansal1999/testing-gh/issues/7) to sbansal1999." - expected_topic = "testing-gh / issue #7 Sample Issue testing something" + expected_message = "sbansal1999 assigned sbansal1999 to [issue #7](https://github.com/sbansal1999/testing-gh/issues/7)." + expected_topic = "testing-gh / issue #7 Testing when issue assigned!" self.check_webhook("issues__assigned", expected_topic, expected_message) def test_issue_assigned_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") expected_topic = "notifications" - expected_message = "sbansal1999 assigned [issue #7 Sample Issue testing something](https://github.com/sbansal1999/testing-gh/issues/7) to sbansal1999." + expected_message = "sbansal1999 assigned sbansal1999 to [issue #7 Testing when issue assigned!](https://github.com/sbansal1999/testing-gh/issues/7)" self.check_webhook("issues__assigned", expected_topic, expected_message) def test_issue_unassigned(self) -> None: diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index 90dd54b4d2..b144f840af 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -170,9 +170,9 @@ def get_issue_body(helper: Helper) -> str: if has_assignee: stringified_assignee = payload["assignee"]["login"].tame(check_string) if action == "assigned": - return f"{base_message[:-1]} to {stringified_assignee}." + return base_message.replace("assigned", f"assigned {stringified_assignee} to", 1) elif action == "unassigned": - return base_message.replace("unassigned", f"unassigned {stringified_assignee} from") + return base_message.replace("unassigned", f"unassigned {stringified_assignee} from", 1) return base_message