Skip to content

Commit f33e927

Browse files
authored
github-automation: Use the llvm/llvm-project repo for backport pull requests (#71727)
Now that the project uses PRs for code review, we don't need to use the llvm/llvm-project-release-prs repo for reviewing backports.
1 parent 3ef20e3 commit f33e927

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

llvm/utils/git/github-automation.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def issue_notify_branch(self) -> None:
444444

445445
def issue_notify_pull_request(self, pull: github.PullRequest.PullRequest) -> None:
446446
self.issue.create_comment(
447-
"/pull-request {}#{}".format(self.branch_repo_name, pull.number)
447+
"/pull-request {}#{}".format(self.repo_name, pull.number)
448448
)
449449

450450
def make_ignore_comment(self, comment: str) -> str:
@@ -496,29 +496,39 @@ def issue_remove_cherry_pick_failed_label(self):
496496
if self.CHERRY_PICK_FAILED_LABEL in [l.name for l in self.issue.labels]:
497497
self.issue.remove_from_labels(self.CHERRY_PICK_FAILED_LABEL)
498498

499+
def get_main_commit(self, cherry_pick_sha: str) -> github.Commit.Commit:
500+
commit = self.repo.get_commit(cherry_pick_sha)
501+
message = commit.commit.message
502+
m = re.search("\(cherry picked from commit ([0-9a-f]+)\)", message)
503+
if not m:
504+
return None
505+
return self.repo.get_commit(m.group(1))
506+
499507
def pr_request_review(self, pr: github.PullRequest.PullRequest):
500508
"""
501509
This function will try to find the best reviewers for `commits` and
502-
then add a comment requesting review of the backport and assign the
503-
pull request to the selected reviewers.
510+
then add a comment requesting review of the backport and add them as
511+
reviewers.
504512
505-
The reviewers selected are those users who approved the patch in
506-
Phabricator.
513+
The reviewers selected are those users who approved the pull request
514+
for the main branch.
507515
"""
508516
reviewers = []
509517
for commit in pr.get_commits():
510-
approvers = phab_get_commit_approvers(self.phab_token, commit)
511-
for a in approvers:
512-
login = phab_login_to_github_login(self.phab_token, self.repo, a)
513-
if not login:
514-
continue
515-
reviewers.append(login)
518+
main_commit = self.get_main_commit(commit.sha)
519+
if not main_commit:
520+
continue
521+
for pull in main_commit.get_pulls():
522+
for review in pull.get_reviews():
523+
if review.state != "APPROVED":
524+
continue
525+
reviewers.append(review.user.login)
516526
if len(reviewers):
517527
message = "{} What do you think about merging this PR to the release branch?".format(
518528
" ".join(["@" + r for r in reviewers])
519529
)
520530
pr.create_issue_comment(message)
521-
pr.add_to_assignees(*reviewers)
531+
pr.create_review_request(reviewers)
522532

523533
def create_branch(self, commits: List[str]) -> bool:
524534
"""
@@ -559,15 +569,15 @@ def check_if_pull_request_exists(
559569

560570
def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
561571
"""
562-
reate a pull request in `self.branch_repo_name`. The base branch of the
572+
Create a pull request in `self.repo_name`. The base branch of the
563573
pull request will be chosen based on the the milestone attached to
564574
the issue represented by `self.issue_number` For example if the milestone
565575
is Release 13.0.1, then the base branch will be release/13.x. `branch`
566576
will be used as the compare branch.
567577
https://docs.github.com/en/get-started/quickstart/github-glossary#base-branch
568578
https://docs.github.com/en/get-started/quickstart/github-glossary#compare-branch
569579
"""
570-
repo = github.Github(self.token).get_repo(self.branch_repo_name)
580+
repo = github.Github(self.token).get_repo(self.repo_name)
571581
issue_ref = "{}#{}".format(self.repo_name, self.issue_number)
572582
pull = None
573583
release_branch_for_issue = self.release_branch_for_issue
@@ -612,9 +622,10 @@ def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
612622
maintainer_can_modify=False,
613623
)
614624

625+
pull.as_issue().edit(milestone=self.issue.milestone)
626+
615627
try:
616-
if self.phab_token:
617-
self.pr_request_review(pull)
628+
self.pr_request_review(pull)
618629
except Exception as e:
619630
print("error: Failed while searching for reviewers", e)
620631

@@ -710,7 +721,7 @@ def execute_command(self) -> bool:
710721
release_workflow_parser.add_argument(
711722
"--branch-repo",
712723
type=str,
713-
default="llvm/llvm-project-release-prs",
724+
default="llvmbot/llvm-project",
714725
help="The name of the repo where new branches will be pushed (e.g. llvm/llvm-project)",
715726
)
716727
release_workflow_parser.add_argument(

0 commit comments

Comments
 (0)