mirror of https://github.com/zulip/zulip.git
parent
8cdc5b7a02
commit
95825973c7
|
@ -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")
|
||||
|
|
|
@ -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']
|
||||
|
|
Loading…
Reference in New Issue