Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 9, 2024

Conversation

tstellar
Copy link
Collaborator

@tstellar tstellar commented Feb 2, 2024

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

:

And a body that says:

Backport ..

Requested By:

…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).
@tstellar tstellar requested review from tru and nikic February 2, 2024 07:53
@tstellar
Copy link
Collaborator Author

tstellar commented Feb 2, 2024

I'm open to suggestions to what the formatting should be for the message. Here is an example of what it looks like with this current patch: tstellar#932

Copy link

github-actions bot commented Feb 2, 2024

✅ With the latest revision this PR passed the Python code formatter.

body = ""
if len(message_lines) > 1:
body = "".join(message_lines.splitlines()[1:])
title = "Backport {} {}".format(" ".join(commits), message_lines[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move the commit ID from the header to the body. That way it will get auto-linked.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is that usually the first commits are tests and the last one the functional patch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests or some other prerequisite that's needed for the fix. It's not always this way, but I'm not sure what else to put in the PR description.

Copy link
Member

@MaskRay MaskRay Feb 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say we have 3 commits. They can be either of test-cleanup test-cleanup functional or functional test-fixup test-fixup or test-cleanup functional test-fixup.

A heuristic: pick the commit with the longest commit message...

@tstellar tstellar changed the title [workflows] Create a more descriptive title and body when creating a … [workflows] Create a more descriptive title and body when creating a PR for backports Feb 4, 2024
@tstellar
Copy link
Collaborator Author

tstellar commented Feb 4, 2024

I think the pull request title is the most important part since that is what shows up in email subjects. So I added the release branch name to the title so it's clear that it's a backport.

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to also add requested by @{} or so here. Currently, I find it hard to keep track of backports that I have requested, because I'm not subscribed to the PRs and don't get notifications about activity.

@llvmbot
Copy link
Member

llvmbot commented Feb 9, 2024

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

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

&lt;release branch&gt;: &lt;First line of HEAD commit for the branch&gt;

And a body that says:

Backport &lt;commit0&gt; &lt;commit1&gt; ..

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 --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())

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well.

@tstellar tstellar merged commit bd65547 into llvm:main Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants