Fix handling of Gitlab payloads with multiple commits
Gitlab sends multiple commits in the order reversed from Github. As this only broke recently, I suspect that they may have changed the ordering. This change makes the code order-agnostic to hopefully remove the problem going forward. Fixes #1900
This commit is contained in:
parent
c43173576a
commit
26e8e241da
3 changed files with 143 additions and 4 deletions
|
@ -104,13 +104,24 @@ def get_transformed_webhook_payload(gl_payload, default_branch=None, lookup_user
|
|||
config['default_branch'] = default_branch
|
||||
config['git_url'] = payload['repository.git_ssh_url']
|
||||
|
||||
config['commit_info.url'] = payload['commits[0].url']
|
||||
config['commit_info.message'] = payload['commits[0].message']
|
||||
config['commit_info.date'] = payload['commits[0].timestamp']
|
||||
# Find the commit associated with the checkout_sha. Gitlab doesn't (necessary) send this in
|
||||
# any order, so we cannot simply index into the commits list.
|
||||
found_commit = None
|
||||
for commit in commits:
|
||||
if commit['id'] == payload['checkout_sha']:
|
||||
found_commit = JSONPathDict(commit)
|
||||
break
|
||||
|
||||
if found_commit is None:
|
||||
raise SkipRequestException
|
||||
|
||||
config['commit_info.url'] = found_commit['url']
|
||||
config['commit_info.message'] = found_commit['message']
|
||||
config['commit_info.date'] = found_commit['timestamp']
|
||||
|
||||
# Note: Gitlab does not send full user information with the payload, so we have to
|
||||
# (optionally) look it up.
|
||||
author_email = payload['commits[0].author.email']
|
||||
author_email = found_commit['author.email']
|
||||
if lookup_user and author_email:
|
||||
author_info = lookup_user(author_email)
|
||||
if author_info:
|
||||
|
|
Reference in a new issue