Merge pull requests from github reporter
Github reporter can be configured to merge pull reqeusts.
When there are multiple merges called at the same time, it leads to a
situation when github returns 405 MethodNotAllowed error becuase github
is checking the branch mergeability.
When we encounter this situation, we try to wait a bit (2 seconds for
now) and try to merge again.
Pre-release version of Github3.py has to be used, because the latest
released version 9.4 has a bug in merge method. Furthermore the newest
merge method supports specifying exact sha to be merged, which is
desirable to ensure that the exact commit that went through the pipeline
gets merged.
Both are already fixed in the stable branch, but not yet released on
PyPi. See:
https://github.com/sigmavirus24/github3.py/commit/90c6b7c2653d65ce686cf4346f9aea9cb9c5c836
https://github.com/sigmavirus24/github3.py/commit/6ef02cb33ff21257eeaf9cab186419ca45ef5806
Change-Id: I0c3abbcce476774a5ba8981c171382eaa4fe0abf
diff --git a/tests/base.py b/tests/base.py
index 0ad1ec1..d7bf467 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -70,6 +70,7 @@
import zuul.merger.server
import zuul.nodepool
import zuul.zk
+from zuul.exceptions import MergeFailure
FIXTURE_DIR = os.path.join(os.path.dirname(__file__),
'fixtures')
@@ -559,6 +560,7 @@
self.statuses = {}
self.updated_at = None
self.head_sha = None
+ self.is_merged = False
self._createPRRef()
self._addCommitToRepo()
self._updateTimeStamp()
@@ -693,6 +695,8 @@
self.pr_number = 0
self.pull_requests = []
self.upstream_root = upstream_root
+ self.merge_failure = False
+ self.merge_not_allowed_count = 0
def openFakePullRequest(self, project, branch):
self.pr_number += 1
@@ -762,6 +766,16 @@
pull_request = self.pull_requests[pr_number - 1]
pull_request.addComment(message)
+ def mergePull(self, project, pr_number, sha=None):
+ pull_request = self.pull_requests[pr_number - 1]
+ if self.merge_failure:
+ raise Exception('Pull request was not merged')
+ if self.merge_not_allowed_count > 0:
+ self.merge_not_allowed_count -= 1
+ raise MergeFailure('Merge was not successful due to mergeability'
+ ' conflict')
+ pull_request.is_merged = True
+
def setCommitStatus(self, project, sha, state,
url='', description='', context=''):
owner, proj = project.split('/')