Normalize github and beanstalk push event subjects.

This commit is contained in:
Tomasz Kolek 2016-10-05 19:26:09 +02:00 committed by Tim Abbott
parent 32934a02e9
commit 1f0f197479
3 changed files with 10 additions and 10 deletions

View File

@ -8,7 +8,7 @@ class BeanstalkHookTests(WebhookTestCase):
def test_git_single(self): def test_git_single(self):
# type: () -> None # type: () -> None
expected_subject = "work-test" expected_subject = "work-test / master"
expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) to branch master expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) to branch master
* [e50508d](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/e50508df): add some stuff * [e50508d](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/e50508df): add some stuff
@ -19,7 +19,7 @@ class BeanstalkHookTests(WebhookTestCase):
def test_git_multiple(self): def test_git_multiple(self):
# type: () -> None # type: () -> None
expected_subject = "work-test" expected_subject = "work-test / master"
expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) to branch master expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) to branch master
* [edf529c](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/edf529c7): Added new file * [edf529c](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/edf529c7): Added new file

View File

@ -61,19 +61,19 @@ class GithubV1HookTests(WebhookTestCase):
def test_user_specified_branches(self): def test_user_specified_branches(self):
# type: () -> None # type: () -> None
self.basic_test('push', 'my_commits', 'zulip-test', self.push_content, self.basic_test('push', 'my_commits', 'zulip-test / master', self.push_content,
send_stream=True, branches="master,staging") send_stream=True, branches="master,staging")
def test_user_specified_stream(self): def test_user_specified_stream(self):
# type: () -> None # type: () -> None
"""Around May 2013 the github webhook started to specify the stream. """Around May 2013 the github webhook started to specify the stream.
Before then, the stream was hard coded to "commits".""" Before then, the stream was hard coded to "commits"."""
self.basic_test('push', 'my_commits', 'zulip-test', self.push_content, self.basic_test('push', 'my_commits', 'zulip-test / master', self.push_content,
send_stream=True) send_stream=True)
def test_legacy_hook(self): def test_legacy_hook(self):
# type: () -> None # type: () -> None
self.basic_test('push', 'commits', 'zulip-test', self.push_content) self.basic_test('push', 'commits', 'zulip-test / master', self.push_content)
def test_issues_opened(self): def test_issues_opened(self):
# type: () -> None # type: () -> None
@ -192,19 +192,19 @@ class GithubV2HookTests(WebhookTestCase):
def test_user_specified_branches(self): def test_user_specified_branches(self):
# type: () -> None # type: () -> None
self.basic_test('push', 'my_commits', 'zulip-test', self.push_content, self.basic_test('push', 'my_commits', 'zulip-test / master', self.push_content,
send_stream=True, branches="master,staging") send_stream=True, branches="master,staging")
def test_user_specified_stream(self): def test_user_specified_stream(self):
# type: () -> None # type: () -> None
"""Around May 2013 the github webhook started to specify the stream. """Around May 2013 the github webhook started to specify the stream.
Before then, the stream was hard coded to "commits".""" Before then, the stream was hard coded to "commits"."""
self.basic_test('push', 'my_commits', 'zulip-test', self.push_content, self.basic_test('push', 'my_commits', 'zulip-test / master', self.push_content,
send_stream=True) send_stream=True)
def test_legacy_hook(self): def test_legacy_hook(self):
# type: () -> None # type: () -> None
self.basic_test('push', 'commits', 'zulip-test', self.push_content) self.basic_test('push', 'commits', 'zulip-test / master', self.push_content)
def test_issues_opened(self): def test_issues_opened(self):
# type: () -> None # type: () -> None

View File

@ -5,7 +5,7 @@ from zerver.lib.response import json_success
from zerver.lib.validator import check_dict from zerver.lib.validator import check_dict
from zerver.decorator import authenticated_api_view, REQ, has_request_variables, to_non_negative_int, flexible_boolean from zerver.decorator import authenticated_api_view, REQ, has_request_variables, to_non_negative_int, flexible_boolean
from zerver.views.messages import send_message_backend from zerver.views.messages import send_message_backend
from zerver.lib.webhooks.git import get_push_commits_event_message from zerver.lib.webhooks.git import get_push_commits_event_message, SUBJECT_WITH_BRANCH_TEMPLATE
import logging import logging
import re import re
import ujson import ujson
@ -225,7 +225,7 @@ def api_github_landing(request, user_profile, event=REQ(),
def build_message_from_gitlog(user_profile, name, ref, commits, before, after, url, pusher, forced=None, created=None): def build_message_from_gitlog(user_profile, name, ref, commits, before, after, url, pusher, forced=None, created=None):
# type: (UserProfile, text_type, text_type, List[Dict[str, str]], text_type, text_type, text_type, text_type, Optional[text_type], Optional[text_type]) -> Tuple[text_type, text_type] # type: (UserProfile, text_type, text_type, List[Dict[str, str]], text_type, text_type, text_type, text_type, Optional[text_type], Optional[text_type]) -> Tuple[text_type, text_type]
short_ref = re.sub(r'^refs/heads/', '', ref) short_ref = re.sub(r'^refs/heads/', '', ref)
subject = name subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref)
if re.match(r'^0+$', after): if re.match(r'^0+$', after):
content = u'%s deleted branch %s' % (pusher, content = u'%s deleted branch %s' % (pusher,