From ce5bb22acea8d1da7b292af540803ec130be0ec8 Mon Sep 17 00:00:00 2001 From: Tomasz Kolek Date: Wed, 26 Oct 2016 21:29:23 +0200 Subject: [PATCH] Normalize comment commit event in github integration. --- zerver/tests/webhooks/test_github.py | 16 ++++++++-------- zerver/views/webhooks/github.py | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/zerver/tests/webhooks/test_github.py b/zerver/tests/webhooks/test_github.py index 4d37a4d518..ba56656be4 100644 --- a/zerver/tests/webhooks/test_github.py +++ b/zerver/tests/webhooks/test_github.py @@ -137,14 +137,14 @@ class GithubV1HookTests(WebhookTestCase): def test_commit_comment(self): # type: () -> None self.basic_test('commit_comment', 'commits', - "zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~") + "zulip-test", + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~") def test_commit_comment_line(self): # type: () -> None self.basic_test('commit_comment_line', 'commits', - "zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on `cowbell`, line 13\n\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~") + "zulip-test", + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~") class GithubV2HookTests(WebhookTestCase): STREAM_NAME = None # type: Optional[text_type] @@ -279,11 +279,11 @@ class GithubV2HookTests(WebhookTestCase): def test_commit_comment(self): # type: () -> None self.basic_test('commit_comment', 'commits', - "zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~") + "zulip-test", + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~") def test_commit_comment_line(self): # type: () -> None self.basic_test('commit_comment_line', 'commits', - "zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", - "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on `cowbell`, line 13\n\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~") + "zulip-test", + "zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252307) on [Commit](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533)\n\n~~~ quote\nThis line adds /unlucky/ cowbell (because of its line number). We should remove it.\n~~~") diff --git a/zerver/views/webhooks/github.py b/zerver/views/webhooks/github.py index 47297a43e3..7702f0f8cf 100644 --- a/zerver/views/webhooks/github.py +++ b/zerver/views/webhooks/github.py @@ -173,17 +173,17 @@ def api_github_v2(user_profile, event, payload, branches, default_stream, forced=payload['forced'], created=payload['created']) elif event == 'commit_comment': - comment = payload['comment'] - subject = u'%s: commit %s' % (topic_focus, comment['commit_id']) + subject = topic_focus - content = (u'%s [commented](%s)' - % (comment['user']['login'], - comment['html_url'])) - - if comment['line'] is not None: - content += u' on `%s`, line %d' % (comment['path'], comment['line']) - - content += u'\n\n~~~ quote\n%s\n~~~' % (comment['body'],) + comment = payload.get('comment') + action = u'[commented]({}) on'.format(comment['html_url']) + content = get_pull_request_event_message( + comment['user']['login'], + action, + comment['html_url'].split('#', 1)[0], + message=comment['body'], + type='Commit' + ) else: raise UnknownEventType(force_str(u'Event %s is unknown and cannot be handled' % (event,)))