github: prevent AttributeError when missing branch protection

It seems like the _getBranchProtection should return an empty dictionary
to prevent:

Traceback (most recent call last):
  File "zuul/scheduler.py", line 883, in run
    self.process_event_queue()
  File "zuul/scheduler.py", line 952, in process_event_queue
    pipeline.manager.addChange(change)
  File "zuul/manager/__init__.py", line 236, in addChange
    if not self.isChangeReadyToBeEnqueued(change):
  File "zuul/manager/dependent.py", line 99, in isChangeReadyToBeEnqueued
    if not source.canMerge(change, self.getSubmitAllowNeeds()):
  File "zuul/driver/github/githubsource.py", line 59, in canMerge
    return self.connection.canMerge(change, allow_needs)
  File "zuul/driver/github/githubconnection.py", line 961, in canMerge
    required_reviews = protection.get(
AttributeError: 'NoneType' object has no attribute 'get'

Change-Id: Ia033da9feac98b28dcf09381fe0f90de76619927
This commit is contained in:
Tristan Cacqueray 2018-06-22 07:00:52 +00:00 committed by Tobias Henkel
parent a5c6c31043
commit e4bca4d24d
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
2 changed files with 7 additions and 3 deletions

View File

@ -152,6 +152,10 @@ class FakeRepository(object):
def get_url_protection(self, branch):
contexts = self.data.required_contexts.get((self.name, branch), [])
if not contexts:
# Note that GitHub returns 404 if branch protection is off so do
# the same here as well
return FakeResponse({}, 404)
data = {
'required_status_checks': {
'contexts': contexts
@ -250,8 +254,8 @@ class FakeIssueSearchResult(object):
class FakeResponse(object):
def __init__(self, data):
self.status_code = 200
def __init__(self, data, status_code=200):
self.status_code = status_code
self.data = data
def json(self):

View File

@ -1061,7 +1061,7 @@ class GithubConnection(BaseConnection):
resp = github.session.get(url, headers=headers)
if resp.status_code == 404:
return None
return {}
return resp.json()