Skip to content

Commit e4d7ddd

Browse files
authored
Parse PR number directly (#263)
1 parent fa7e702 commit e4d7ddd

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ branch, and start working on a fresh branch.
5151

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

5657
## Structure of submitted pull requests
5758

ghstack/github_utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,23 @@ def get_github_repo_info(
115115
)
116116

117117

118-
def parse_pull_request(pull_request: str) -> GitHubPullRequestParams:
118+
def parse_pull_request(
119+
pull_request: str,
120+
*,
121+
sh: Optional[ghstack.shell.Shell] = None,
122+
remote_name: Optional[str] = None,
123+
) -> GitHubPullRequestParams:
119124
m = RE_PR_URL.match(pull_request)
120125
if not m:
126+
# We can reconstruct the URL if just a PR number is passed
127+
if sh is not None and remote_name is not None:
128+
remote_url = sh.git("remote", "get-url", remote_name)
129+
# Do not pass the shell to avoid infinite loop
130+
try:
131+
return parse_pull_request(remote_url + "/pull/" + pull_request)
132+
except RuntimeError:
133+
# Fall back on original error message
134+
pass
121135
raise RuntimeError("Did not understand PR argument. PR must be URL")
122136

123137
github_url = m.group("github_url")

ghstack/land.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def main(
5757
# Furthermore, the parent commits of PR are ignored: we always
5858
# take the canonical version of the patch from any given pr
5959

60-
params = ghstack.github_utils.parse_pull_request(pull_request)
60+
params = ghstack.github_utils.parse_pull_request(
61+
pull_request, sh=sh, remote_name=remote_name
62+
)
6163
default_branch = ghstack.github_utils.get_github_repo_info(
6264
github=github,
6365
sh=sh,

0 commit comments

Comments
 (0)