From e4d7ddd3ec150210f78047cd3c0763f2438ab6b4 Mon Sep 17 00:00:00 2001 From: Vincent Moens Date: Thu, 24 Oct 2024 16:02:11 +0100 Subject: [PATCH] Parse PR number directly (#263) --- README.md | 3 ++- ghstack/github_utils.py | 16 +++++++++++++++- ghstack/land.py | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 46b2098..6e182be 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ghstack/github_utils.py b/ghstack/github_utils.py index f8000ac..ecb4b70 100644 --- a/ghstack/github_utils.py +++ b/ghstack/github_utils.py @@ -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") diff --git a/ghstack/land.py b/ghstack/land.py index 56ee6a0..73b61ae 100644 --- a/ghstack/land.py +++ b/ghstack/land.py @@ -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,