Fix Gitlab trigger payload bug when commits is empty
Gitlab will occasionally send trigger payloads with an empty commit list (and a null checkout_ha) for branches that have been deleted. Properly handle that case.
This commit is contained in:
parent
b4dd5ea4dd
commit
c43173576a
3 changed files with 66 additions and 3 deletions
|
@ -28,7 +28,7 @@ GITLAB_WEBHOOK_PAYLOAD_SCHEMA = {
|
|||
'type': 'string',
|
||||
},
|
||||
'checkout_sha': {
|
||||
'type': 'string',
|
||||
'type': ['string', 'null'],
|
||||
},
|
||||
'repository': {
|
||||
'type': 'object',
|
||||
|
@ -65,8 +65,7 @@ GITLAB_WEBHOOK_PAYLOAD_SCHEMA = {
|
|||
},
|
||||
'required': ['url', 'message', 'timestamp'],
|
||||
},
|
||||
'minItems': 1,
|
||||
}
|
||||
},
|
||||
},
|
||||
'required': ['ref', 'checkout_sha', 'repository'],
|
||||
}
|
||||
|
@ -94,6 +93,11 @@ def get_transformed_webhook_payload(gl_payload, default_branch=None, lookup_user
|
|||
|
||||
payload = JSONPathDict(gl_payload)
|
||||
|
||||
# Check for empty commits. The commits list will be empty if the branch is deleted.
|
||||
commits = payload['commits']
|
||||
if not commits:
|
||||
raise SkipRequestException
|
||||
|
||||
config = SafeDictSetter()
|
||||
config['commit'] = payload['checkout_sha']
|
||||
config['ref'] = payload['ref']
|
||||
|
|
Reference in a new issue