[llvm] github-automation: Use the llvm/llvm-project repo for backport pull requests (PR #71727)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 11:28:37 PST 2023


https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/71727

>From a2d6420fc435dd410fa0ef2badd7f99a1c09c157 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Mon, 9 Oct 2023 16:24:35 -0700
Subject: [PATCH 1/2] github-automation: Use the llvm/llvm-project repo for
 backport pull requests

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.
---
 llvm/utils/git/github-automation.py | 45 ++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index ad1878d41193920..fef5a902398b3b2 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -415,7 +415,7 @@ def issue_notify_branch(self) -> None:
 
     def issue_notify_pull_request(self, pull: github.PullRequest.PullRequest) -> None:
         self.issue.create_comment(
-            "/pull-request {}#{}".format(self.branch_repo_name, pull.number)
+            "/pull-request {}#{}".format(self.repo_name, pull.number)
         )
 
     def make_ignore_comment(self, comment: str) -> str:
@@ -467,29 +467,39 @@ def issue_remove_cherry_pick_failed_label(self):
         if self.CHERRY_PICK_FAILED_LABEL in [l.name for l in self.issue.labels]:
             self.issue.remove_from_labels(self.CHERRY_PICK_FAILED_LABEL)
 
+    def get_main_commit(self, cherry_pick_sha: str) -> github.Commit.Commit:
+        commit = self.repo.get_commit(cherry_pick_sha)
+        message = commit.commit.message
+        m = re.search('\(cherry picked from commit ([0-9a-f]+)\)', message)
+        if not m:
+            return None
+        return self.repo.get_commit(m.group(1))
+
     def pr_request_review(self, pr: github.PullRequest.PullRequest):
         """
         This function will try to find the best reviewers for `commits` and
-        then add a comment requesting review of the backport and assign the
-        pull request to the selected reviewers.
+        then add a comment requesting review of the backport and add them as
+        reviewers.
 
-        The reviewers selected are those users who approved the patch in
-        Phabricator.
+        The reviewers selected are those users who approved the pull request
+        for the main branch.
         """
         reviewers = []
         for commit in pr.get_commits():
-            approvers = phab_get_commit_approvers(self.phab_token, commit)
-            for a in approvers:
-                login = phab_login_to_github_login(self.phab_token, self.repo, a)
-                if not login:
-                    continue
-                reviewers.append(login)
+            main_commit = self.get_main_commit(commit.sha)
+            if not main_commit:
+                continue
+            for pull in main_commit.get_pulls():
+                for review in pull.get_reviews():
+                    if review.state != 'APPROVED':
+                        continue
+                reviewers.append(review.user.login)
         if len(reviewers):
             message = "{} What do you think about merging this PR to the release branch?".format(
                 " ".join(["@" + r for r in reviewers])
             )
             pr.create_issue_comment(message)
-            pr.add_to_assignees(*reviewers)
+            pr.create_review_request(reviewers)
 
     def create_branch(self, commits: List[str]) -> bool:
         """
@@ -530,7 +540,7 @@ def check_if_pull_request_exists(
 
     def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
         """
-        reate a pull request in `self.branch_repo_name`.  The base branch of the
+        Create a pull request in `self.repo_name`.  The base branch of the
         pull request will be chosen based on the the milestone attached to
         the issue represented by `self.issue_number`  For example if the milestone
         is Release 13.0.1, then the base branch will be release/13.x. `branch`
@@ -538,7 +548,7 @@ def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
         https://docs.github.com/en/get-started/quickstart/github-glossary#base-branch
         https://docs.github.com/en/get-started/quickstart/github-glossary#compare-branch
         """
-        repo = github.Github(self.token).get_repo(self.branch_repo_name)
+        repo = github.Github(self.token).get_repo(self.repo_name)
         issue_ref = "{}#{}".format(self.repo_name, self.issue_number)
         pull = None
         release_branch_for_issue = self.release_branch_for_issue
@@ -583,9 +593,10 @@ def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
                 maintainer_can_modify=False,
             )
 
+            pull.as_issue().edit(milestone = self.issue.milestone)
+
             try:
-                if self.phab_token:
-                    self.pr_request_review(pull)
+                self.pr_request_review(pull)
             except Exception as e:
                 print("error: Failed while searching for reviewers", e)
 
@@ -678,7 +689,7 @@ def execute_command(self) -> bool:
 release_workflow_parser.add_argument(
     "--branch-repo",
     type=str,
-    default="llvm/llvm-project-release-prs",
+    default="llvmbot/llvm-project",
     help="The name of the repo where new branches will be pushed (e.g. llvm/llvm-project)",
 )
 release_workflow_parser.add_argument(

>From 2c8c0e93c51d6a41b0c1d6ab6e0fcdc8f1f62d41 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Wed, 8 Nov 2023 11:28:05 -0800
Subject: [PATCH 2/2] Fix python formatting errors

---
 llvm/utils/git/github-automation.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index fef5a902398b3b2..6dca0e80de74ac6 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -470,7 +470,7 @@ def issue_remove_cherry_pick_failed_label(self):
     def get_main_commit(self, cherry_pick_sha: str) -> github.Commit.Commit:
         commit = self.repo.get_commit(cherry_pick_sha)
         message = commit.commit.message
-        m = re.search('\(cherry picked from commit ([0-9a-f]+)\)', message)
+        m = re.search("\(cherry picked from commit ([0-9a-f]+)\)", message)
         if not m:
             return None
         return self.repo.get_commit(m.group(1))
@@ -491,7 +491,7 @@ def pr_request_review(self, pr: github.PullRequest.PullRequest):
                 continue
             for pull in main_commit.get_pulls():
                 for review in pull.get_reviews():
-                    if review.state != 'APPROVED':
+                    if review.state != "APPROVED":
                         continue
                 reviewers.append(review.user.login)
         if len(reviewers):
@@ -593,7 +593,7 @@ def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
                 maintainer_can_modify=False,
             )
 
-            pull.as_issue().edit(milestone = self.issue.milestone)
+            pull.as_issue().edit(milestone=self.issue.milestone)
 
             try:
                 self.pr_request_review(pull)



More information about the llvm-commits mailing list