mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
webhooks: Fix handling of GitLab Job Hook events.
This fixes an exception for these events. Fixture from https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#job-events.
This commit is contained in:
@@ -547,6 +547,14 @@ class GitlabHookTests(WebhookTestCase):
|
|||||||
self.assertFalse(check_send_webhook_message_mock.called)
|
self.assertFalse(check_send_webhook_message_mock.called)
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
|
|
||||||
|
def test_job_hook_event(self) -> None:
|
||||||
|
expected_topic = "gitlab_test / gitlab-script-trigger"
|
||||||
|
expected_message = "Build test from test stage was created."
|
||||||
|
self.send_and_test_stream_message(
|
||||||
|
'job_hook__build_created',
|
||||||
|
expected_topic,
|
||||||
|
expected_message)
|
||||||
|
|
||||||
def test_system_push_event_message(self) -> None:
|
def test_system_push_event_message(self) -> None:
|
||||||
expected_topic = "gitlab / master"
|
expected_topic = "gitlab / master"
|
||||||
expected_message = "John Smith [pushed](http://test.example.com/gitlab/gitlab/compare/95790bf891e76fee5e1747ab589903a6a1f80f22...da1560886d4f094c3e6c9ef40349f7d38b5d27d7) 1 commit to branch master. Commits by Test User (1).\n\n* Add simple search to projects in public area ([c5feabd](https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428))"
|
expected_message = "John Smith [pushed](http://test.example.com/gitlab/gitlab/compare/95790bf891e76fee5e1747ab589903a6a1f80f22...da1560886d4f094c3e6c9ef40349f7d38b5d27d7) 1 commit to branch master. Commits by Test User (1).\n\n* Add simple search to projects in public area ([c5feabd](https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428))"
|
||||||
|
|||||||
@@ -273,7 +273,13 @@ def get_pipeline_event_body(payload: Dict[str, Any]) -> str:
|
|||||||
return "[Pipeline]({}) {} with build(s):\n{}.".format(pipeline_url, action, builds_status[:-1])
|
return "[Pipeline]({}) {} with build(s):\n{}.".format(pipeline_url, action, builds_status[:-1])
|
||||||
|
|
||||||
def get_repo_name(payload: Dict[str, Any]) -> str:
|
def get_repo_name(payload: Dict[str, Any]) -> str:
|
||||||
return payload['project']['name']
|
if 'project' in payload:
|
||||||
|
return payload['project']['name']
|
||||||
|
|
||||||
|
# Apparently, Job Hook payloads don't have a `project` section,
|
||||||
|
# but the repository name is accessible from the `repository`
|
||||||
|
# section.
|
||||||
|
return payload['repository']['name']
|
||||||
|
|
||||||
def get_user_name(payload: Dict[str, Any]) -> str:
|
def get_user_name(payload: Dict[str, Any]) -> str:
|
||||||
return payload['user_name']
|
return payload['user_name']
|
||||||
|
|||||||
Reference in New Issue
Block a user