MCPcopy Create free account
hub / github.com/ezyang/ghstack / rest

Method rest

src/ghstack/github_fake.py:460–538  ·  view source on GitHub ↗
(self, method: str, path: str, **kwargs: Any)

Source from the content-addressed store, hash-verified

458 repo.defaultBranchRef = repo._make_ref(state, input["default_branch"])
459
460 def rest(self, method: str, path: str, **kwargs: Any) -> Any:
461 if method == "get":
462 m = re.match(r"^repos/([^/]+)/([^/]+)/branches/([^/]+)/protection", path)
463 if m:
464 # For now, pretend all branches are not protected
465 raise ghstack.github.NotFoundError()
466 if m := re.match(r"^repos/([^/]+)/([^/]+)/pulls/([^/]+)$", path):
467 state = self.state
468 repo = state.repository(m.group(1), m.group(2))
469 pr = state.pull_request(repo, GitHubNumber(int(m.group(3))))
470 return {
471 "number": pr.number,
472 "state": "closed" if pr.closed else "open",
473 "title": pr.title,
474 "body": pr.body,
475 }
476 if m := re.match(r"^repos/([^/]+)/([^/]+)/issues/comments/([^/]+)$", path):
477 state = self.state
478 repo = state.repository(m.group(1), m.group(2))
479 comment = state.issue_comment(repo, int(m.group(3)))
480 return {
481 "id": comment.fullDatabaseId,
482 "body": comment.body,
483 }
484
485 elif method == "post":
486 if m := re.match(r"^repos/([^/]+)/([^/]+)/pulls$", path):
487 return self._create_pull(
488 m.group(1), m.group(2), cast(CreatePullRequestInput, kwargs)
489 )
490 if m := re.match(r"^repos/([^/]+)/([^/]+)/issues/([^/]+)/comments", path):
491 return self._create_issue_comment(
492 m.group(1),
493 m.group(2),
494 GitHubNumber(int(m.group(3))),
495 cast(CreateIssueCommentInput, kwargs),
496 )
497 if m := re.match(
498 r"^repos/([^/]+)/([^/]+)/pulls/([^/]+)/requested_reviewers", path
499 ):
500 # Handle adding reviewers
501 state = self.state
502 repo = state.repository(m.group(1), m.group(2))
503 pr = state.pull_request(repo, GitHubNumber(int(m.group(3))))
504 reviewers = kwargs.get("reviewers", [])
505 pr.reviewers.extend(reviewers)
506 return {}
507 if m := re.match(r"^repos/([^/]+)/([^/]+)/issues/([^/]+)/labels", path):
508 # Handle adding labels
509 state = self.state
510 repo = state.repository(m.group(1), m.group(2))
511 pr = state.pull_request(repo, GitHubNumber(int(m.group(3))))
512 labels = kwargs.get("labels", [])
513 pr.labels.extend(labels)
514 return {}
515 elif method == "patch":
516 if m := re.match(r"^repos/([^/]+)/([^/]+)(?:/pulls/([^/]+))?$", path):
517 owner, name, number = m.groups()

Callers

nothing calls this directly

Calls 10

_create_pullMethod · 0.95
_create_issue_commentMethod · 0.95
_update_pullMethod · 0.95
_set_default_branchMethod · 0.95
_update_issue_commentMethod · 0.95
pull_requestMethod · 0.80
issue_commentMethod · 0.80
formatMethod · 0.80
repositoryMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected