Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions eden/scm/sapling/ext/github/consts/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@
}
"""

GRAPHQL_ADD_COMMENT = """
mutation ($subjectId: ID!, $body: String!) {
addComment(input: {subjectId: $subjectId, body: $body}) {
commentEdge {
node {
id
}
}
}
}
"""

GRAPHQL_CREATE_BRANCH = """
mutation ($repositoryId: ID!, $name: String!, $oid: GitObjectID!) {
createRef(input: {repositoryId: $repositoryId, name: $name, oid: $oid}) {
Expand Down
14 changes: 14 additions & 0 deletions eden/scm/sapling/ext/github/gh_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ async def update_pull_request(
return Ok(result.unwrap()["data"]["updatePullRequest"]["pullRequest"]["id"])


async def add_comment(hostname: str, subject_id: str, body: str) -> Result[str, str]:
"""Adds a comment to an issue or pull request, returning the comment node ID."""
params: Dict[str, _Params] = {
"query": query.GRAPHQL_ADD_COMMENT,
"subjectId": subject_id,
"body": body,
}
result = await gh_cli.make_request(params, hostname=hostname)
if result.is_err():
return Err(result.unwrap_err())
else:
return Ok(result.unwrap()["data"]["addComment"]["commentEdge"]["node"]["id"])


async def create_branch(
*, hostname: str, repo_id: str, branch_name: str, oid: str
) -> Result[str, str]:
Expand Down
38 changes: 37 additions & 1 deletion eden/scm/sapling/ext/github/mock_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def expect_update_pr_request(
) -> "UpdatePrRequest":
if not stack_pr_ids:
stack_pr_ids = [pr_number]
stack_pr_ids = list(reversed(sorted(stack_pr_ids)))
stack_pr_ids = sorted(stack_pr_ids, reverse=True)

if len(stack_pr_ids) > 1:
pr_list = [
Expand All @@ -313,6 +313,19 @@ def expect_update_pr_request(
self._add_request(key, request)
return request

def expect_add_comment_request(
self, pr_id: str, body: str
) -> "AddCommentRequest":
params: ParamsType = {
"query": query.GRAPHQL_ADD_COMMENT,
"subjectId": pr_id,
"body": body,
}
key = create_request_key(params, self.hostname)
request = AddCommentRequest(key, pr_id)
self._add_request(key, request)
return request

def expect_get_username_request(
self,
) -> "GetUsernameRequest":
Expand Down Expand Up @@ -545,6 +558,29 @@ def get_response(self) -> Result[JsonDict, str]:
return self._response


class AddCommentRequest(MockRequest):
def __init__(self, key: str, pr_id: str) -> None:
self._key = key
self._response: Optional[Result[JsonDict, str]] = None

self._pr_id = pr_id

def and_respond(self):
data = {
"data": {
"addComment": {
"commentEdge": {"node": {"id": f"comment_{self._pr_id}"}}
}
}
}
self._response = Ok(data)

def get_response(self) -> Result[JsonDict, str]:
if self._response is None:
raise MockResponseNotSet(self._key)
return self._response


class GetUsernameRequest(MockRequest):
def __init__(self, key: str) -> None:
self._key = key
Expand Down
Loading
Loading