def merge_ghstack_into(self, repo: GitRepo, force: bool, comment_id: Optional[int] = None) -> None: assert self.is_ghstack_pr() approved_by = self.get_approved_by() # For ghstack, cherry-pick commits based from origin orig_ref = f"{repo.remote}/{re.sub(r'/head$', '/orig', self.head_ref())}" rev_list = repo.revlist(f"{self.default_branch()}..{orig_ref}") for idx, rev in enumerate(reversed(rev_list)): msg = repo.commit_message(rev) m = RE_PULL_REQUEST_RESOLVED.search(msg) if m is None: raise RuntimeError(f"Could not find PR-resolved string in {msg} of ghstacked PR {self.pr_num}") if self.org != m.group('owner') or self.project != m.group('repo'): raise RuntimeError(f"PR {m.group('number')} resolved to wrong owner/repo pair") pr_num = int(m.group('number')) if pr_num != self.pr_num: pr = GitHubPR(self.org, self.project, pr_num) if pr.is_closed(): print(f"Skipping {idx+1} of {len(rev_list)} PR (#{pr_num}) as its already been merged") continue approved_by = pr.get_approved_by() # Raises exception if matching rule is not found find_matching_merge_rule(pr, repo, force=force, skip_internal_checks=can_skip_internal_checks(self, comment_id)) # Adding the url here makes it clickable within the Github UI approved_by_urls = ', '.join(prefix_with_github_url(login) for login in approved_by) repo.cherry_pick(rev) msg = re.sub(RE_GHSTACK_SOURCE_ID, "", msg) msg += f"\nApproved by: {approved_by_urls}\n" repo.amend_commit_message(msg)
def merge_ghstack_into(self, repo: GitRepo) -> None: assert self.is_ghstack_pr() # For ghstack, cherry-pick commits based from origin orig_ref = f"{repo.remote}/{re.sub(r'/head$', '/orig', self.head_ref())}" rev_list = repo.revlist(f"{self.default_branch()}..{orig_ref}") for idx, rev in enumerate(reversed(rev_list)): msg = repo.commit_message(rev) m = RE_PULL_REQUEST_RESOLVED.search(msg) if m is None: raise RuntimeError( f"Could not find PR-resolved string in {msg} of ghstacked PR {self.pr_num}" ) if self.org != m.group('owner') or self.project != m.group('repo'): raise RuntimeError( f"PR {m.group('number')} resolved to wrong owner/repo pair" ) pr_num = int(m.group('number')) if pr_num != self.pr_num: pr = GitHubPR(self.org, self.project, pr_num) if pr.is_closed(): print( f"Skipping {idx+1} of {len(rev_list)} PR (#{pr_num}) as its already been merged" ) continue # Raises exception if matching rule is not found find_matching_merge_rule(pr, repo) repo.cherry_pick(rev) repo.amend_commit_message(re.sub(RE_GHSTACK_SOURCE_ID, "", msg))