diff options
author | Zuul <zuul@review.opendev.org> | 2020-10-02 11:12:58 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-10-02 11:12:58 +0000 |
commit | 212ed78502612b147463c247fadd2e7ed599cb2d (patch) | |
tree | d51d4461b1c865bdfa9c4feadff06b1ac8ff0ef6 /tests/fakegithub.py | |
parent | 14a86c4d89f332b18e061d9fa01fbd8dfc2c2351 (diff) | |
parent | eed5820fb3269099d1ef5bd0d50a96edee52bd47 (diff) | |
download | zuul-212ed78502612b147463c247fadd2e7ed599cb2d.tar.gz |
Merge "Optimize GitHub requests on PR merge"
Diffstat (limited to 'tests/fakegithub.py')
-rw-r--r-- | tests/fakegithub.py | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/tests/fakegithub.py b/tests/fakegithub.py index 8e2f275eb..2c226fe4f 100644 --- a/tests/fakegithub.py +++ b/tests/fakegithub.py @@ -518,24 +518,6 @@ class FakePull(object): # with the head_sha as the only commit return [self.head] - def merge(self, commit_message=None, sha=None, merge_method=None): - conn = self._fake_pull_request.github - pr = self._fake_pull_request - - # record that this got reported - conn.github_data.reports.append( - (pr.project, pr.number, 'merge', merge_method)) - if conn.merge_failure: - raise Exception('Unknown merge failure') - if conn.merge_not_allowed_count > 0: - conn.merge_not_allowed_count -= 1 - resp = ErrorResponse() - resp.status_code = 403 - resp.message = 'Merge not allowed' - raise github3.exceptions.MethodNotAllowed(resp) - pr.setMerged(commit_message) - return True - def as_dict(self): pr = self._fake_pull_request connection = pr.github @@ -669,6 +651,31 @@ class FakeGithubSession(object): return FakeResponse(None, 404) + def put(self, url, data=None, headers=None, params=None, json=None): + # Handle pull request merge + match = re.match(r'.+/repos/(.+)/pulls/(\d+)/merge$', url) + if match: + project, pr_number = match.groups() + project = urllib.parse.unquote(project) + pr = self.client._data.pull_requests[int(pr_number)] + conn = pr.github + + # record that this got reported + self.client._data.reports.append( + (pr.project, pr.number, 'merge', json["merge_method"])) + if conn.merge_failure: + raise Exception('Unknown merge failure') + if conn.merge_not_allowed_count > 0: + conn.merge_not_allowed_count -= 1 + resp = ErrorResponse() + resp.status_code = 403 + resp.message = 'Merge not allowed' + raise github3.exceptions.MethodNotAllowed(resp) + pr.setMerged(json["commit_message"]) + return FakeResponse({"merged": True}, 200) + + return FakeResponse(None, 404) + def get_repo(self, request, params=None): org, project, request = request.split('/', 2) project_name = '{}/{}'.format(org, project) |