Skip to content
Snippets Groups Projects
Commit 1c2e75c9b593 authored by Georges Racinet's avatar Georges Racinet
Browse files

Post receive hook: adapted to payload of GitLab 12.3

The API JSON payload for the post-receive endpoint has changed:
messages categorization is simpler (`basic` or `alert`) and they
are preformatted.

We still support the GitLab 12.2 style
parent b5091b393a30
No related branches found
No related tags found
No related merge requests found
Pipeline #5331 passed
......@@ -247,6 +247,18 @@
warnings = as_json.get('warnings')
if warnings is not None:
out_lines.extend(format_warnings(warnings))
# GitLab 12.3: MR links as messages with type 'basic',
# broadcasts and warnings as type 'alert'
# basic treatment, probably won't be very pretty, but good enough
# for now.
messages = as_json.get('messages', ())
for message in messages:
if message.get(u'type') == u'basic':
out_lines.append(message['message'].encode('utf-8'))
alert = '\n'.join(m['message'].encode('utf-8')
for m in messages if m.get(u'type') == u'alert')
if alert:
out_lines.extend(format_alert_message(alert))
return '\n'.join(out_lines)
def pre_receive_params(self, changes, env=None):
......
......@@ -121,7 +121,7 @@
assert params['project'] == repo.root
def test_post_receive_handle_response(tmpdir):
def test_post_receive_handle_response_gl_12_2(tmpdir):
wrapper = make_repo(tmpdir, 'proj.hg')
repo = wrapper.repo
hook = Hook('post-receive', repo)
......@@ -169,6 +169,37 @@
assert any(warnings in l for l in out)
def test_post_receive_handle_response_gl_12_3(tmpdir):
wrapper = make_repo(tmpdir, 'proj.hg')
repo = wrapper.repo
hook = Hook('post-receive', repo)
out = hook.post_receive_handle_response(
# example taken from the functional tests
{u'messages': [
{u'message': (
u'To create a merge request '
u'for topic/default/ant, visit:\n'
u'http://localhost:3000/root/test_project/merge_requests/new'
u'?merge_request%5Bsource_branch%5D=topic%2Fdefault%2Fant'
),
u'type': u'basic',
},
{u'message': u'This is a TESTING SERVER',
u'type': u'alert',
},
]})
out = [l.strip() for l in out.splitlines() if l.strip()]
assert out == [
'To create a merge request for topic/default/ant, visit:',
'http://localhost:3000/root/test_project/merge_requests/new'
'?merge_request%5Bsource_branch%5D=topic%2Fdefault%2Fant',
'=' * 72,
'This is a TESTING SERVER',
'=' * 72,
]
def test_integration_post_receive(tmpdir, monkeypatch):
records = []
responses = [make_json_response(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment