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

Function main

src/ghstack/land.py:45–229  ·  view source on GitHub ↗
(
    pull_request: str,
    remote_name: str,
    github: ghstack.github.GitHubEndpoint,
    sh: ghstack.shell.Shell,
    github_url: str,
    *,
    force: bool = False,
)

Source from the content-addressed store, hash-verified

43
44
45def main(
46 pull_request: str,
47 remote_name: str,
48 github: ghstack.github.GitHubEndpoint,
49 sh: ghstack.shell.Shell,
50 github_url: str,
51 *,
52 force: bool = False,
53) -> None:
54
55 # We land the entire stack pointed to by a URL.
56 # Local state is ignored; PR is source of truth
57 # Furthermore, the parent commits of PR are ignored: we always
58 # take the canonical version of the patch from any given pr
59
60 params = ghstack.github_utils.parse_pull_request(
61 pull_request, sh=sh, remote_name=remote_name
62 )
63 default_branch = ghstack.github_utils.get_github_repo_info(
64 github=github,
65 sh=sh,
66 repo_owner=params["owner"],
67 repo_name=params["name"],
68 github_url=github_url,
69 remote_name=remote_name,
70 )["default_branch"]
71
72 needs_force = False
73 try:
74 protection = github.get(
75 f"repos/{params['owner']}/{params['name']}/branches/{default_branch}/protection"
76 )
77 if not protection["allow_force_pushes"]["enabled"]:
78 raise RuntimeError(
79 """\
80Default branch {default_branch} is protected, and doesn't allow force pushes.
81ghstack land does not work. You will not be able to land your ghstack; please
82resubmit your PRs using the normal pull request flow.
83
84See https://github.com/ezyang/ghstack/issues/50 for more details, or
85to complain to the ghstack authors."""
86 )
87 else:
88 needs_force = True
89 except ghstack.github.NotFoundError:
90 pass
91
92 orig_ref, closed = lookup_pr_to_orig_ref_and_closed(
93 github,
94 owner=params["owner"],
95 name=params["name"],
96 number=params["number"],
97 )
98
99 if closed:
100 raise RuntimeError("PR is already closed, cannot land it!")
101
102 if sh is None:

Callers

nothing calls this directly

Calls 4

gitMethod · 0.95
getMethod · 0.45
notify_mergedMethod · 0.45

Tested by

no test coverage detected