Normalize comment commit event in github integration.

This commit is contained in:
Tomasz Kolek
2016-10-26 21:29:23 +02:00
committed by Tim Abbott
parent 6ad4cce35c
commit ce5bb22ace
2 changed files with 18 additions and 18 deletions

View File

@@ -137,14 +137,14 @@ class GithubV1HookTests(WebhookTestCase):
def test_commit_comment(self): def test_commit_comment(self):
# type: () -> None # type: () -> None
self.basic_test('commit_comment', 'commits', self.basic_test('commit_comment', 'commits',
"zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", "zulip-test",
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~") "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): def test_commit_comment_line(self):
# type: () -> None # type: () -> None
self.basic_test('commit_comment_line', 'commits', self.basic_test('commit_comment_line', 'commits',
"zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", "zulip-test",
"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~~~") "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): class GithubV2HookTests(WebhookTestCase):
STREAM_NAME = None # type: Optional[text_type] STREAM_NAME = None # type: Optional[text_type]
@@ -279,11 +279,11 @@ class GithubV2HookTests(WebhookTestCase):
def test_commit_comment(self): def test_commit_comment(self):
# type: () -> None # type: () -> None
self.basic_test('commit_comment', 'commits', self.basic_test('commit_comment', 'commits',
"zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", "zulip-test",
"zbenjamin [commented](https://github.com/zbenjamin/zulip-test/commit/7c994678d2f98797d299abed852d3ff9d0834533#commitcomment-4252302)\n\n~~~ quote\nAre we sure this is enough cowbell?\n~~~") "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): def test_commit_comment_line(self):
# type: () -> None # type: () -> None
self.basic_test('commit_comment_line', 'commits', self.basic_test('commit_comment_line', 'commits',
"zulip-test: commit 7c994678d2f98797d299abed852d3ff9d0834533", "zulip-test",
"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~~~") "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~~~")

View File

@@ -173,17 +173,17 @@ def api_github_v2(user_profile, event, payload, branches, default_stream,
forced=payload['forced'], forced=payload['forced'],
created=payload['created']) created=payload['created'])
elif event == 'commit_comment': elif event == 'commit_comment':
comment = payload['comment'] subject = topic_focus
subject = u'%s: commit %s' % (topic_focus, comment['commit_id'])
content = (u'%s [commented](%s)' comment = payload.get('comment')
% (comment['user']['login'], action = u'[commented]({}) on'.format(comment['html_url'])
comment['html_url'])) content = get_pull_request_event_message(
comment['user']['login'],
if comment['line'] is not None: action,
content += u' on `%s`, line %d' % (comment['path'], comment['line']) comment['html_url'].split('#', 1)[0],
message=comment['body'],
content += u'\n\n~~~ quote\n%s\n~~~' % (comment['body'],) type='Commit'
)
else: else:
raise UnknownEventType(force_str(u'Event %s is unknown and cannot be handled' % (event,))) raise UnknownEventType(force_str(u'Event %s is unknown and cannot be handled' % (event,)))