Merge "Improve function to find PR from commit status" into feature/zuulv3
diff --git a/tests/base.py b/tests/base.py
index 357dd7a..c49e1ce 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -967,6 +967,7 @@
data = {
'state': state,
'sha': self.head_sha,
+ 'name': self.project,
'description': 'Test results for %s: %s' % (self.head_sha, state),
'target_url': 'http://zuul/%s' % self.head_sha,
'branches': [],
@@ -1088,8 +1089,9 @@
}
return data
- def getPullBySha(self, sha):
- prs = list(set([p for p in self.pull_requests if sha == p.head_sha]))
+ def getPullBySha(self, sha, project):
+ prs = list(set([p for p in self.pull_requests if
+ sha == p.head_sha and project == p.project]))
if len(prs) > 1:
raise Exception('Multiple pulls found with head sha: %s' % sha)
pr = prs[0]
diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py
index bac66f1..015ba0d 100644
--- a/zuul/driver/github/githubconnection.py
+++ b/zuul/driver/github/githubconnection.py
@@ -252,7 +252,8 @@
action = body.get('action')
if action == 'pending':
return
- pr_body = self.connection.getPullBySha(body['sha'])
+ project = body.get('name')
+ pr_body = self.connection.getPullBySha(body['sha'], project)
if pr_body is None:
return
@@ -760,18 +761,12 @@
# For now, just send back a True value.
return True
- def getPullBySha(self, sha):
- query = '%s type:pr is:open' % sha
+ def getPullBySha(self, sha, project):
pulls = []
- github = self.getGithubClient()
- for issue in github.search_issues(query=query):
- pr_url = issue.issue.pull_request().as_dict().get('url')
- if not pr_url:
- continue
- # the issue provides no good description of the project :\
- owner, project, _, number = pr_url.split('/')[-4:]
- github = self.getGithubClient("%s/%s" % (owner, project))
- pr = github.pull_request(owner, project, number)
+ owner, project = project.split('/')
+ github = self.getGithubClient("%s/%s" % (owner, project))
+ repo = github.repository(owner, project)
+ for pr in repo.pull_requests(state='open'):
if pr.head.sha != sha:
continue
if pr.as_dict() in pulls: