From 5cfebfa3eda63f1351e53e04d811dd5999ab0e87 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 13 Feb 2019 11:17:19 -0800 Subject: [PATCH] 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 --- tests/base.py | 3 ++- tests/fakegithub.py | 10 +--------- zuul/driver/github/githubconnection.py | 10 ++-------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/tests/base.py b/tests/base.py index 869835f204..3d7c457383 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1096,7 +1096,8 @@ class FakeGithubPullRequest(object): }, 'sender': { 'login': 'ghuser' - } + }, + 'labels': [{'name': l} for l in self.labels] } return (name, data) diff --git a/tests/fakegithub.py b/tests/fakegithub.py index 93d280c442..3c73ebc22a 100644 --- a/tests/fakegithub.py +++ b/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 diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py index 33bdc0d6e1..e75c3d9ebc 100644 --- a/zuul/driver/github/githubconnection.py +++ b/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)