From 636dad78098fca7b1422b879f07b9d3fbb718828 Mon Sep 17 00:00:00 2001 From: "Hemanth V. Alluri" Date: Tue, 2 Apr 2019 00:03:51 +0530 Subject: [PATCH] webhooks/bitbucket3: Use strikethrough formatting for deleted comments. --- zerver/webhooks/bitbucket3/tests.py | 4 ++-- zerver/webhooks/bitbucket3/view.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/zerver/webhooks/bitbucket3/tests.py b/zerver/webhooks/bitbucket3/tests.py index 035ffa8d0c..8f7a55f632 100644 --- a/zerver/webhooks/bitbucket3/tests.py +++ b/zerver/webhooks/bitbucket3/tests.py @@ -22,7 +22,7 @@ class Bitbucket3HookTests(WebhookTestCase): expected_message) def test_commit_comment_deleted(self) -> None: - expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted their comment on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907)\n~~~ quote\nJust an arbitrary comment on a commit. Nothing to see here...\n~~~""" + expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted their comment on [508d1b6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/commits/508d1b67f1f8f3a25f543a030a7a178894aa9907)\n~~~ quote\n~~Just an arbitrary comment on a commit. Nothing to see here...~~\n~~~""" self.send_and_test_stream_message("commit_comment_deleted", self.EXPECTED_TOPIC, expected_message) @@ -264,7 +264,7 @@ class Bitbucket3HookTests(WebhookTestCase): expected_message) def test_pull_request_comment_deleted(self) -> None: - expected_message = """[zura](http://139.59.64.214:7990/users/zura) deleted their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)\n\n~~~ quote\nThis seems like a pretty good idea. @shimura what do you think?\n~~~""" + expected_message = """[zura](http://139.59.64.214:7990/users/zura) deleted their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6)\n\n~~~ quote\n~~This seems like a pretty good idea. @shimura what do you think?~~\n~~~""" expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." self.send_and_test_stream_message("pull_request_comment_deleted", expected_topic, diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.py index f7d544932c..71347bfffe 100644 --- a/zerver/webhooks/bitbucket3/view.py +++ b/zerver/webhooks/bitbucket3/view.py @@ -48,12 +48,15 @@ def repo_comment_handler(payload: Dict[str, Any], action: str) -> List[Dict[str, sha = payload["commit"] commit_url = payload["repository"]["links"]["self"][0]["href"][:-6] # remove the "browse" at the end commit_url += "commits/%s" % (sha,) + message = payload["comment"]["text"] + if action == "deleted their comment": + message = "~~{message}~~".format(message=message) body = get_commits_comment_action_message( user_name=get_user_name(payload), action=action, commit_url=commit_url, sha=sha, - message=payload["comment"]["text"] + message=message ) return [{"subject": subject, "body": body}] @@ -275,6 +278,8 @@ def pr_comment_handler(payload: Dict[str, Any], action: str, subject = get_pr_subject(pr["toRef"]["repository"]["name"], type="PR", id=pr["id"], title=pr["title"]) message = payload["comment"]["text"] + if action == "deleted their comment on": + message = "~~{message}~~".format(message=message) body = get_pull_request_event_message( user_name=get_user_name(payload), action=action,