From b6b5f9aa5401e7e712b4786ced0f77e1f6bcda37 Mon Sep 17 00:00:00 2001 From: Cullen Taylor Date: Tue, 18 Apr 2017 09:37:04 -0500 Subject: [PATCH] Report to pulls with identical SHAs It is possible to run into a scenario where two different pulls have the same SHA. We should report to these pulls and tell them to amend their change. Implements: BonnyCI/projman#127 Signed-off-by: Cullen Taylor --- tests/test_github.py | 24 ++++++++++++++++++++++++ zuul/connection/github.py | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/tests/test_github.py b/tests/test_github.py index 4501124c9e..e52e65f559 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -527,3 +527,27 @@ def test_failed_change_at_head(self): self.assertNotIn('merge', A.labels) self.assertNotIn('merge', B.labels) self.assertNotIn('merge', C.labels) + + def test_multiple_pulls(self): + self.worker.hold_jobs_in_build = True + self.create_branch('org/project', 'pr_branch_A') + self.create_branch('org/project', 'pr_branch_B') + A = self.fake_github.openFakePullRequest('org/project', 'pr_branch_A', + 'A') + B = self.fake_github.openFakePullRequest('org/project', 'pr_branch_B', + 'B') + self.fake_github.emitEvent(A.getPullRequestOpenedEvent()) + self.fake_github.emitEvent(B.getPullRequestOpenedEvent()) + self.waitUntilSettled() + + self.worker.hold_jobs_in_build = False + self.worker.release() + self.waitUntilSettled() + self.fake_github.emitEvent(A.addLabel('merge')) + self.fake_github.emitEvent(B.addLabel('merge')) + self.waitUntilSettled() + + self.assertThat(A.comments[0], + MatchesRegex('.*Multiple pulls.*', re.DOTALL)) + self.assertThat(B.comments[0], + MatchesRegex('.*Multiple pulls.*', re.DOTALL)) diff --git a/zuul/connection/github.py b/zuul/connection/github.py index 571dbb54bc..9819b47bfa 100644 --- a/zuul/connection/github.py +++ b/zuul/connection/github.py @@ -565,6 +565,10 @@ def getPullBySha(self, sha): pulls.append(pr.as_dict()) if len(pulls) > 1: + for pull in pulls: + self.commentPull(pull.owner, pull.project, pull.pr_number, + 'Multiple pulls found with head sha %s. ' + 'Please amend your change.' % sha) raise Exception('Multiple pulls found with head sha %s' % sha) log_rate_limit(self.log, github)