Add branch name to topic in Gitlab integration.

Fixes: #1831.
This commit is contained in:
Tomasz Kolek 2016-09-22 20:15:06 +02:00 committed by Tim Abbott
parent 8cdc5b7a02
commit 95825973c7
2 changed files with 8 additions and 2 deletions

View File

@ -8,7 +8,7 @@ class GitlabHookTests(WebhookTestCase):
def test_push_event_message(self):
# type: () -> None
expected_subject = u"Repository: my-awesome-project"
expected_subject = u"Repository: my-awesome-project - branch: tomek"
expected_message = u"Tomasz Kolek pushed [2 commits](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) to tomek branch."
self.send_and_test_stream_message('push', expected_subject, expected_message, HTTP_X_GITLAB_EVENT="Push Hook")

View File

@ -184,7 +184,7 @@ def api_gitlab_webhook(request, user_profile, client,
# type: (HttpRequest, UserProfile, Client, text_type, Dict[str, Any]) -> HttpResponse
event = get_event(request, payload)
body = get_body_based_on_event(event)(payload)
subject = "Repository: {}".format(get_repo_name(payload))
subject = get_subject_based_on_event(event, payload)
check_send_message(user_profile, client, 'stream', [stream], subject, body)
return json_success()
@ -192,6 +192,12 @@ def get_body_based_on_event(event):
# type: (str) -> Any
return EVENT_FUNCTION_MAPPER[event]
def get_subject_based_on_event(event, payload):
# type: (str, Dict[str, Any]) -> str
if event == 'Push Hook':
return "Repository: {} - branch: {}".format(get_repo_name(payload), get_branch_name(payload))
return "Repository: {}".format(get_repo_name(payload))
def get_event(request, payload):
# type: (HttpRequest, Dict[str, Any]) -> str
event = request.META['HTTP_X_GITLAB_EVENT']