Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkout PR number #264

Merged
merged 5 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion ghstack/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def main(
remote_name: str,
) -> None:

params = ghstack.github_utils.parse_pull_request(pull_request)
params = ghstack.github_utils.parse_pull_request(
pull_request, sh=sh, remote_name=remote_name
)
head_ref = github.get_head_ref(**params)
orig_ref = re.sub(r"/head$", "/orig", head_ref)
if orig_ref == head_ref:
Expand Down
18 changes: 16 additions & 2 deletions ghstack/github_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_github_repo_name_with_owner(
# Grovel in remotes to figure it out
remote_url = sh.git("remote", "get-url", remote_name)
while True:
match = r"^git@{github_url}:/?([^/]+)/(.+?)(?:\.git)?$".format(
match = r"^git@{github_url}:([^/]+)/(.+?)(?:\.git)?$".format(
github_url=github_url
)
m = re.match(match, remote_url)
Expand Down 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
Loading