[GH1] Enable cross-repo merges

GHStack based PRs still can not be cross-repo, but for regular ones
checkout `pull/{pr_no}/head`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/72750
This commit is contained in:
Nikita Shulga
2022-02-11 22:49:47 +00:00
committed by PyTorch MergeBot
parent 340fae4363
commit 0c95209fe7
2 changed files with 9 additions and 4 deletions

View File

@ -303,7 +303,9 @@ class GitHubPR:
if not self.is_ghstack_pr():
msg = self.get_title() + "\n\n" + self.get_body()
msg += f"\nPull Request resolved: {self.get_pr_url()}\n"
repo._run_git("merge", "--squash", f"{repo.remote}/{self.head_ref()}")
pr_branch_name = f"__pull-request-{self.pr_num}__init__"
repo.fetch(f"pull/{self.pr_num}/head", pr_branch_name)
repo._run_git("merge", "--squash", pr_branch_name)
repo._run_git("commit", f"--author=\"{self.get_author()}\"", "-m", msg)
else:
self.merge_ghstack_into(repo)
@ -422,8 +424,8 @@ def main() -> None:
gh_post_comment(org, project, args.pr_num, f"Can't merge closed PR #{args.pr_num}", dry_run=args.dry_run)
return
if pr.is_cross_repo():
gh_post_comment(org, project, args.pr_num, "Cross-repo merges are not supported at the moment", dry_run=args.dry_run)
if pr.is_cross_repo() and pr.is_ghstack_pr():
gh_post_comment(org, project, args.pr_num, "Cross-repo ghstack merges are not supported", dry_run=args.dry_run)
return
try: