Log missing required status checks

When required status checks are missing this is not mentioned in the
logs which can make it difficult to find out from the logs why a
change didn't enter the gate.

Change-Id: Ifc8a5d5406acbada1ec8d9d07ce03887c4e7b261
This commit is contained in:
Tobias Henkel 2020-04-07 15:46:18 +02:00
parent 1e767220fb
commit a143fafd0f
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
1 changed files with 10 additions and 6 deletions

View File

@ -1559,7 +1559,11 @@ class GithubConnection(BaseConnection):
log.debug('Change %s can not merge because it is a draft', change)
return False
if not self._hasRequiredStatusChecks(allow_needs, canmerge_data):
missing_status_checks = self._getMissingStatusChecks(
allow_needs, canmerge_data)
if missing_status_checks:
log.debug('Change %s can not merge because required status checks '
'are missing: %s', change, missing_status_checks)
return False
if canmerge_data.get('requiresApprovingReviews'):
@ -1679,11 +1683,11 @@ class GithubConnection(BaseConnection):
return resp.json()
@staticmethod
def _hasRequiredStatusChecks(allow_needs, canmerge_data):
def _getMissingStatusChecks(allow_needs, canmerge_data):
required_contexts = canmerge_data['requiredStatusCheckContexts']
if not required_contexts:
# There are no required contexts -> ok by definition
return True
return set()
# Strip allow_needs as we will set this in the gate ourselves
required_contexts = set(
@ -1693,9 +1697,9 @@ class GithubConnection(BaseConnection):
successful = set([s[0] for s in canmerge_data['status'].items()
if s[1] == 'SUCCESS'])
# Required contexts must be a subset of the successful contexts as
# we allow additional successful status contexts we don't care about.
return required_contexts.issubset(successful)
# Remove successful checks from the required contexts to get the
# remaining missing required status.
return required_contexts.difference(successful)
@cachetools.cached(cache=cachetools.TTLCache(maxsize=2048, ttl=3600),
key=lambda self, login, project: