Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
vmoens committed Oct 21, 2024
1 parent fa7e702 commit 3330f1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 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
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
2 changes: 1 addition & 1 deletion ghstack/land.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ 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 3330f1f

Please sign in to comment.