(
pull_request: str,
remote_name: str,
github: ghstack.github.GitHubEndpoint,
sh: ghstack.shell.Shell,
github_url: str,
*,
force: bool = False,
)
| 43 | |
| 44 | |
| 45 | def 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 | """\ |
| 80 | Default branch {default_branch} is protected, and doesn't allow force pushes. |
| 81 | ghstack land does not work. You will not be able to land your ghstack; please |
| 82 | resubmit your PRs using the normal pull request flow. |
| 83 | |
| 84 | See https://github.com/ezyang/ghstack/issues/50 for more details, or |
| 85 | to 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: |
nothing calls this directly
no test coverage detected