[llvm] [workflows] Create a more descriptive title and body when creating a PR for backports (PR #80396)

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 16:23:20 PST 2024


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

>From 5c1774f408b2c45a353a2a5a538d25a2787e384a Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 2 Feb 2024 07:17:36 +0000
Subject: [PATCH 1/5] [workflows] Create a more descriptive title and body when
 creating a PR for backports

When a backport request is made, the resulting pull request will have a
title like this:

Backport <commit> <commit> .. <First line of HEAD commit for the branch>

And a body that is the commit message of the HEAD commit for the branch
(minus the first line).
---
 llvm/utils/git/github-automation.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 04698cacbff92..f7eaf1f3ec550 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -536,7 +536,7 @@ def create_branch(self, commits: List[str]) -> bool:
 
         self.issue_remove_cherry_pick_failed_label()
         return self.create_pull_request(
-            self.branch_repo_owner, self.repo_name, branch_name
+            self.branch_repo_owner, self.repo_name, branch_name, commits
         )
 
     def check_if_pull_request_exists(
@@ -545,7 +545,7 @@ def check_if_pull_request_exists(
         pulls = repo.get_pulls(head=head)
         return pulls.totalCount != 0
 
-    def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
+    def create_pull_request(self, owner: str, repo_name: str, branch: str, commits: List[str]) -> bool:
         """
         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
@@ -567,9 +567,15 @@ def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
             print("PR already exists...")
             return True
         try:
+            commit_message = repo.get_commit(commits[-1]).commit.message
+            message_lines = commit_message.splitlines()
+            body = ""
+            if len(message_lines) > 1:
+                body = "".join(message_lines.splitlines()[1:])
+            title = "Backport {} {}".format(" ".join(commits), message_lines[0])
             pull = repo.create_pull(
-                title=f"PR for {issue_ref}",
-                body="resolves {}".format(issue_ref),
+                title=title,
+                body=body,
                 base=release_branch_for_issue,
                 head=head,
                 maintainer_can_modify=False,

>From 90ed7c04f5c7ec5190899703fb6ec11ace8f9826 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Sat, 3 Feb 2024 23:38:10 +0000
Subject: [PATCH 2/5] Adjust title and description

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

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index f7eaf1f3ec550..0610d40b64ac7 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -569,10 +569,8 @@ def create_pull_request(self, owner: str, repo_name: str, branch: str, commits:
         try:
             commit_message = repo.get_commit(commits[-1]).commit.message
             message_lines = commit_message.splitlines()
-            body = ""
-            if len(message_lines) > 1:
-                body = "".join(message_lines.splitlines()[1:])
-            title = "Backport {} {}".format(" ".join(commits), message_lines[0])
+            title = "{}: {}".format(release_branch_for_issue, message_lines[0])
+            body = "Backport {}".format(" ".join(commits))
             pull = repo.create_pull(
                 title=title,
                 body=body,

>From e5b51613c120e08f9b1e472eaf64ee7e745c2704 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Sun, 4 Feb 2024 00:20:30 +0000
Subject: [PATCH 3/5] Fix formatting

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

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 0610d40b64ac7..c9ab1783daba8 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -545,7 +545,9 @@ def check_if_pull_request_exists(
         pulls = repo.get_pulls(head=head)
         return pulls.totalCount != 0
 
-    def create_pull_request(self, owner: str, repo_name: str, branch: str, commits: List[str]) -> bool:
+    def create_pull_request(
+        self, owner: str, repo_name: str, branch: str, commits: List[str]
+    ) -> bool:
         """
         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

>From 3c54d159301a7ceba60681edf26c4ae64f5888b8 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Tue, 6 Feb 2024 01:42:43 +0000
Subject: [PATCH 4/5] Add requested by comment

---
 .github/workflows/issue-release-workflow.yml |  1 +
 llvm/utils/git/github-automation.py          | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/issue-release-workflow.yml b/.github/workflows/issue-release-workflow.yml
index 33a1e89a729f6..448c1c56f897f 100644
--- a/.github/workflows/issue-release-workflow.yml
+++ b/.github/workflows/issue-release-workflow.yml
@@ -65,4 +65,5 @@ jobs:
           release-workflow \
           --branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
           --issue-number ${{ github.event.issue.number }} \
+          --requested-by ${{ github.event.issue.user.login }} \
           auto
diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index c9ab1783daba8..15ba6a2dc6d88 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -343,6 +343,7 @@ def __init__(
         branch_repo_name: str,
         branch_repo_token: str,
         llvm_project_dir: str,
+        requested_by: str
     ) -> None:
         self._token = token
         self._repo_name = repo
@@ -353,6 +354,7 @@ def __init__(
         else:
             self._branch_repo_token = self.token
         self._llvm_project_dir = llvm_project_dir
+        self._requested_by = requested_by
 
     @property
     def token(self) -> str:
@@ -382,6 +384,10 @@ def branch_repo_token(self) -> str:
     def llvm_project_dir(self) -> str:
         return self._llvm_project_dir
 
+    @property
+    def requested_by(self) -> str:
+        return self._requested_by
+
     @property
     def repo(self) -> github.Repository.Repository:
         return github.Github(self.token).get_repo(self.repo_name)
@@ -572,7 +578,7 @@ def create_pull_request(
             commit_message = repo.get_commit(commits[-1]).commit.message
             message_lines = commit_message.splitlines()
             title = "{}: {}".format(release_branch_for_issue, message_lines[0])
-            body = "Backport {}".format(" ".join(commits))
+            body = "Backport {}\n\nRequested by: @{}".format(" ".join(commits), self.requested_by)
             pull = repo.create_pull(
                 title=title,
                 body=body,
@@ -685,6 +691,9 @@ def execute_command(self) -> bool:
     "setup-llvmbot-git",
     help="Set the default user and email for the git repo in LLVM_PROJECT_DIR to llvmbot",
 )
+release_workflow_parser.add_argument(
+    "--requested-by", type=str, required=True,
+    help="The user that requested this backport")
 
 args = parser.parse_args()
 
@@ -714,6 +723,7 @@ def execute_command(self) -> bool:
         args.branch_repo,
         args.branch_repo_token,
         args.llvm_project_dir,
+        args.requested_by
     )
     if not release_workflow.release_branch_for_issue:
         release_workflow.issue_notify_no_milestone(sys.stdin.readlines())

>From fd613f1e27371195728b8ff29d730bb63baa1868 Mon Sep 17 00:00:00 2001
From: Tom Stellard <tstellar at redhat.com>
Date: Fri, 9 Feb 2024 00:18:48 +0000
Subject: [PATCH 5/5] Fix formatting

---
 llvm/utils/git/github-automation.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/llvm/utils/git/github-automation.py b/llvm/utils/git/github-automation.py
index 15ba6a2dc6d88..aa849d98ad7b8 100755
--- a/llvm/utils/git/github-automation.py
+++ b/llvm/utils/git/github-automation.py
@@ -343,7 +343,7 @@ def __init__(
         branch_repo_name: str,
         branch_repo_token: str,
         llvm_project_dir: str,
-        requested_by: str
+        requested_by: str,
     ) -> None:
         self._token = token
         self._repo_name = repo
@@ -578,7 +578,9 @@ def create_pull_request(
             commit_message = repo.get_commit(commits[-1]).commit.message
             message_lines = commit_message.splitlines()
             title = "{}: {}".format(release_branch_for_issue, message_lines[0])
-            body = "Backport {}\n\nRequested by: @{}".format(" ".join(commits), self.requested_by)
+            body = "Backport {}\n\nRequested by: @{}".format(
+                " ".join(commits), self.requested_by
+            )
             pull = repo.create_pull(
                 title=title,
                 body=body,
@@ -692,8 +694,11 @@ def execute_command(self) -> bool:
     help="Set the default user and email for the git repo in LLVM_PROJECT_DIR to llvmbot",
 )
 release_workflow_parser.add_argument(
-    "--requested-by", type=str, required=True,
-    help="The user that requested this backport")
+    "--requested-by",
+    type=str,
+    required=True,
+    help="The user that requested this backport"
+)
 
 args = parser.parse_args()
 
@@ -723,7 +728,7 @@ def execute_command(self) -> bool:
         args.branch_repo,
         args.branch_repo_token,
         args.llvm_project_dir,
-        args.requested_by
+        args.requested_by,
     )
     if not release_workflow.release_branch_for_issue:
         release_workflow.issue_notify_no_milestone(sys.stdin.readlines())



More information about the llvm-commits mailing list