github: add merge into branch request for MockGitHubServer

Summary: as title

Reviewed By: bolinfest

Differential Revision: D42116786

fbshipit-source-id: 61c0cc1b8d64fb73e0a10ebd627faf3ae6795cec
This commit is contained in:
Zhaolong Zhu 2022-12-19 06:13:27 -08:00 committed by Facebook GitHub Bot
parent e02a3873ee
commit a7bee24f4d
2 changed files with 40 additions and 0 deletions

View File

@ -198,6 +198,25 @@ class MockGitHubServer:
self._add_request(key, request)
return request
def expect_merge_into_branch(
self,
head: str,
username: str = USER_NAME,
repo_id: str = REPO_ID,
base: str = "",
) -> "MergeIntoBranchRequest":
base = base or f"sapling-pr-archive-{username}"
params: ParamsType = {
"query": query.GRAPHQL_MERGE_BRANCH,
"repositoryId": repo_id,
"base": base,
"head": head,
}
key = create_request_key(params, self.hostname)
request = MergeIntoBranchRequest(key, head)
self._add_request(key, request)
return request
class MockRequest:
@abstractmethod
@ -354,6 +373,24 @@ class GetUsernameRequest(MockRequest):
return self._response
class MergeIntoBranchRequest(MockRequest):
def __init__(self, key: str, head: str) -> None:
self._key = key
self._response: Optional[Result] = None
self._head = head
def and_respond(self, merge_commit_oid: str = ""):
merge_commit_oid = merge_commit_oid or gen_hash_hexdigest(self._head)
data = {"data": {"mergeBranch": {"mergeCommit": {"oid": merge_commit_oid}}}}
self._response = Result.Ok(data)
def get_response(self) -> Result:
if self._response is None:
raise MockResponseNotSet(self._key)
return self._response
class MockRequestNotFound(Exception):
pass

View File

@ -33,6 +33,9 @@ def setup_mock_github_server() -> MockGitHubServer:
github_server.expect_update_pr_request(pr_id, pr_number, body).and_respond()
github_server.expect_get_username_request().and_respond()
head = "3a120a3a153f7d2960967ce6f1d52698a4d3a436"
github_server.expect_merge_into_branch(head).and_respond()
return github_server