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
This commit is contained in:
parent
2495512589
commit
5cfebfa3ed
|
@ -1096,7 +1096,8 @@ class FakeGithubPullRequest(object):
|
||||||
},
|
},
|
||||||
'sender': {
|
'sender': {
|
||||||
'login': 'ghuser'
|
'login': 'ghuser'
|
||||||
}
|
},
|
||||||
|
'labels': [{'name': l} for l in self.labels]
|
||||||
}
|
}
|
||||||
return (name, data)
|
return (name, data)
|
||||||
|
|
||||||
|
|
|
@ -262,11 +262,6 @@ class FakeRepository(object):
|
||||||
return pulls
|
return pulls
|
||||||
|
|
||||||
|
|
||||||
class FakeLabel(object):
|
|
||||||
def __init__(self, name):
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
|
|
||||||
class FakeIssue(object):
|
class FakeIssue(object):
|
||||||
def __init__(self, fake_pull_request):
|
def __init__(self, fake_pull_request):
|
||||||
self._fake_pull_request = fake_pull_request
|
self._fake_pull_request = fake_pull_request
|
||||||
|
@ -274,10 +269,6 @@ class FakeIssue(object):
|
||||||
def pull_request(self):
|
def pull_request(self):
|
||||||
return FakePull(self._fake_pull_request)
|
return FakePull(self._fake_pull_request)
|
||||||
|
|
||||||
def labels(self):
|
|
||||||
return [FakeLabel(l)
|
|
||||||
for l in self._fake_pull_request.labels]
|
|
||||||
|
|
||||||
|
|
||||||
class FakeFile(object):
|
class FakeFile(object):
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
|
@ -338,6 +329,7 @@ class FakePull(object):
|
||||||
'merged': pr.is_merged,
|
'merged': pr.is_merged,
|
||||||
'body': pr.body,
|
'body': pr.body,
|
||||||
'changed_files': len(pr.files),
|
'changed_files': len(pr.files),
|
||||||
|
'labels': [{'name': l} for l in pr.labels]
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
|
@ -1132,10 +1132,6 @@ class GithubConnection(BaseConnection):
|
||||||
self.log.warning("Pull request #%s of %s/%s returned None!" % (
|
self.log.warning("Pull request #%s of %s/%s returned None!" % (
|
||||||
number, owner, proj))
|
number, owner, proj))
|
||||||
time.sleep(1)
|
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()
|
pr = probj.as_dict()
|
||||||
try:
|
try:
|
||||||
pr['files'] = [f.filename for f in probj.files()]
|
pr['files'] = [f.filename for f in probj.files()]
|
||||||
|
@ -1147,10 +1143,8 @@ class GithubConnection(BaseConnection):
|
||||||
"via the merger: %s", exc)
|
"via the merger: %s", exc)
|
||||||
pr['files'] = []
|
pr['files'] = []
|
||||||
|
|
||||||
pr['labels'] = [l.name for l in issueobj.labels()]
|
labels = [l['name'] for l in pr['labels']]
|
||||||
|
pr['labels'] = labels
|
||||||
self._sha_pr_cache.update(project_name, pr)
|
|
||||||
|
|
||||||
log.debug('Got PR %s#%s', project_name, number)
|
log.debug('Got PR %s#%s', project_name, number)
|
||||||
self.log_rate_limit(self.log, github)
|
self.log_rate_limit(self.log, github)
|
||||||
return (pr, probj)
|
return (pr, probj)
|
||||||
|
|
Loading…
Reference in New Issue