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

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 16:14:25 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

<details>
<summary>Changes</summary>

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

<release branch>: <First line of HEAD commit for the branch>

And a body that says:

Backport <commit0> <commit1> ..
```

---
Full diff: https://github.com/llvm/llvm-project/pull/80396.diff


2 Files Affected:

- (modified) .github/workflows/issue-release-workflow.yml (+1) 
- (modified) llvm/utils/git/github-automation.py (+20-4) 


``````````diff
diff --git a/.github/workflows/issue-release-workflow.yml b/.github/workflows/issue-release-workflow.yml
index 33a1e89a729f6b..448c1c56f897f5 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 04698cacbff929..15ba6a2dc6d886 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)
@@ -536,7 +542,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 +551,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) -> 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 +575,13 @@ 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()
+            title = "{}: {}".format(release_branch_for_issue, message_lines[0])
+            body = "Backport {}\n\nRequested by: @{}".format(" ".join(commits), self.requested_by)
             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,
@@ -679,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()
 
@@ -708,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())

``````````

</details>


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


More information about the llvm-commits mailing list