Skip to content

Commit

Permalink
Parse PR number directly (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens authored Oct 24, 2024
1 parent fa7e702 commit e4d7ddd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ branch, and start working on a fresh branch.

**WARNING.** You will NOT be able to merge these commits using the
normal GitHub UI, as their branch bases won't be master. Use
`ghstack land $PR_URL` to land a ghstack'ed pull request.
`ghstack land $PR_URL` (or alternatively `ghtstack land #PR_NUM`) to land
a ghstack'ed pull request.

## Structure of submitted pull requests

Expand Down
16 changes: 15 additions & 1 deletion ghstack/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,23 @@ def get_github_repo_info(
)


def parse_pull_request(pull_request: str) -> GitHubPullRequestParams:
def parse_pull_request(
pull_request: str,
*,
sh: Optional[ghstack.shell.Shell] = None,
remote_name: Optional[str] = None,
) -> GitHubPullRequestParams:
m = RE_PR_URL.match(pull_request)
if not m:
# We can reconstruct the URL if just a PR number is passed
if sh is not None and remote_name is not None:
remote_url = sh.git("remote", "get-url", remote_name)
# Do not pass the shell to avoid infinite loop
try:
return parse_pull_request(remote_url + "/pull/" + pull_request)
except RuntimeError:
# Fall back on original error message
pass
raise RuntimeError("Did not understand PR argument. PR must be URL")

github_url = m.group("github_url")
Expand Down
4 changes: 3 additions & 1 deletion ghstack/land.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def main(
# Furthermore, the parent commits of PR are ignored: we always
# take the canonical version of the patch from any given pr

params = ghstack.github_utils.parse_pull_request(pull_request)
params = ghstack.github_utils.parse_pull_request(
pull_request, sh=sh, remote_name=remote_name
)
default_branch = ghstack.github_utils.get_github_repo_info(
github=github,
sh=sh,
Expand Down

0 comments on commit e4d7ddd

Please sign in to comment.