Browse Source

Don't request PR issue data

The github api docs show that labels is now part of the PR dict returned
in pulls API responses. github3 doesn't directly expose this as an
attribute but we can use the as_dict representation to access any json
field. Use this field on the PR dict repr to access the labels of a PR
and stop fetching the issue of a PR for that info.

Change-Id: Ib14bb387dbd233ff252cf57be7f0517770ade037
changes/28/636728/5
Clark Boylan 3 years ago
parent
commit
5cfebfa3ed
  1. 3
      tests/base.py
  2. 10
      tests/fakegithub.py
  3. 10
      zuul/driver/github/githubconnection.py

3
tests/base.py

@ -1096,7 +1096,8 @@ class FakeGithubPullRequest(object):
},
'sender': {
'login': 'ghuser'
}
},
'labels': [{'name': l} for l in self.labels]
}
return (name, data)

10
tests/fakegithub.py

@ -262,11 +262,6 @@ class FakeRepository(object):
return pulls
class FakeLabel(object):
def __init__(self, name):
self.name = name
class FakeIssue(object):
def __init__(self, fake_pull_request):
self._fake_pull_request = fake_pull_request
@ -274,10 +269,6 @@ class FakeIssue(object):
def pull_request(self):
return FakePull(self._fake_pull_request)
def labels(self):
return [FakeLabel(l)
for l in self._fake_pull_request.labels]
class FakeFile(object):
def __init__(self, filename):
@ -338,6 +329,7 @@ class FakePull(object):
'merged': pr.is_merged,
'body': pr.body,
'changed_files': len(pr.files),
'labels': [{'name': l} for l in pr.labels]
}
return data

10
zuul/driver/github/githubconnection.py

@ -1132,10 +1132,6 @@ class GithubConnection(BaseConnection):
self.log.warning("Pull request #%s of %s/%s returned None!" % (
number, owner, proj))
time.sleep(1)
# Get the issue obj so we can get the labels (this is silly)
# TODO: this may be able to be simplified after
# https://github.com/sigmavirus24/github3.py/issues/924
issueobj = probj.issue()
pr = probj.as_dict()
try:
pr['files'] = [f.filename for f in probj.files()]
@ -1147,10 +1143,8 @@ class GithubConnection(BaseConnection):
"via the merger: %s", exc)
pr['files'] = []
pr['labels'] = [l.name for l in issueobj.labels()]
self._sha_pr_cache.update(project_name, pr)
labels = [l['name'] for l in pr['labels']]
pr['labels'] = labels
log.debug('Got PR %s#%s', project_name, number)
self.log_rate_limit(self.log, github)
return (pr, probj)

Loading…
Cancel
Save