webhooks/bitbucket2: Improve commit_status_changed type messages.

Instead of just referring to the commit with the raw URL, we
should use the commit ID as the text of the hyperlink.

Note that in commit_status_changed type messages, the name of the
commit isn't available.
This commit is contained in:
Eeshan Garg 2018-09-22 18:27:45 -02:30 committed by Rishi Gupta
parent b22254835e
commit 9e625b881b
2 changed files with 5 additions and 4 deletions

View File

@ -84,7 +84,7 @@ class Bitbucket2HookTests(WebhookTestCase):
self.send_and_test_stream_message('commit_comment_created', self.EXPECTED_SUBJECT, expected_message) self.send_and_test_stream_message('commit_comment_created', self.EXPECTED_SUBJECT, expected_message)
def test_bitbucket2_on_commit_status_changed_event(self) -> None: def test_bitbucket2_on_commit_status_changed_event(self) -> None:
expected_message = u"[System mybuildtool](https://my-build-tool.com/builds/MY-PROJECT/BUILD-777) changed status of https://bitbucket.org/kolaszek/repository-name/commits/9fec847784abb10b2fa567ee63b85bd238955d0e to SUCCESSFUL." expected_message = u"[System mybuildtool](https://my-build-tool.com/builds/MY-PROJECT/BUILD-777) changed status of [9fec847](https://bitbucket.org/kolaszek/repository-name/commits/9fec847784abb10b2fa567ee63b85bd238955d0e) to SUCCESSFUL."
self.send_and_test_stream_message('commit_status_changed', self.EXPECTED_SUBJECT, expected_message) self.send_and_test_stream_message('commit_status_changed', self.EXPECTED_SUBJECT, expected_message)
def test_bitbucket2_on_issue_created_event(self) -> None: def test_bitbucket2_on_issue_created_event(self) -> None:

View File

@ -229,9 +229,10 @@ def get_commit_status_changed_body(payload: Dict[str, Any]) -> str:
commit_api_url = payload['commit_status']['links']['commit']['href'] commit_api_url = payload['commit_status']['links']['commit']['href']
commit_id = commit_api_url.split('/')[-1] commit_id = commit_api_url.split('/')[-1]
commit_info = "{}/commits/{}".format( commit_info = "[{short_commit_id}]({repo_url}/commits/{commit_id})".format(
get_repository_url(payload['repository']), repo_url=get_repository_url(payload['repository']),
commit_id short_commit_id=commit_id[:7],
commit_id=commit_id
) )
return BITBUCKET_COMMIT_STATUS_CHANGED_BODY.format( return BITBUCKET_COMMIT_STATUS_CHANGED_BODY.format(