Skip to content

Commit bd65547

Browse files
authored
[workflows] Create a more descriptive title and body when creating a PR for backports (#80396)
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> .. Requested By: <user>
1 parent 228e9d5 commit bd65547

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

.github/workflows/issue-release-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ jobs:
6565
release-workflow \
6666
--branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
6767
--issue-number ${{ github.event.issue.number }} \
68+
--requested-by ${{ github.event.issue.user.login }} \
6869
auto

llvm/utils/git/github-automation.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def __init__(
343343
branch_repo_name: str,
344344
branch_repo_token: str,
345345
llvm_project_dir: str,
346+
requested_by: str,
346347
) -> None:
347348
self._token = token
348349
self._repo_name = repo
@@ -353,6 +354,7 @@ def __init__(
353354
else:
354355
self._branch_repo_token = self.token
355356
self._llvm_project_dir = llvm_project_dir
357+
self._requested_by = requested_by
356358

357359
@property
358360
def token(self) -> str:
@@ -382,6 +384,10 @@ def branch_repo_token(self) -> str:
382384
def llvm_project_dir(self) -> str:
383385
return self._llvm_project_dir
384386

387+
@property
388+
def requested_by(self) -> str:
389+
return self._requested_by
390+
385391
@property
386392
def repo(self) -> github.Repository.Repository:
387393
return github.Github(self.token).get_repo(self.repo_name)
@@ -536,7 +542,7 @@ def create_branch(self, commits: List[str]) -> bool:
536542

537543
self.issue_remove_cherry_pick_failed_label()
538544
return self.create_pull_request(
539-
self.branch_repo_owner, self.repo_name, branch_name
545+
self.branch_repo_owner, self.repo_name, branch_name, commits
540546
)
541547

542548
def check_if_pull_request_exists(
@@ -545,7 +551,9 @@ def check_if_pull_request_exists(
545551
pulls = repo.get_pulls(head=head)
546552
return pulls.totalCount != 0
547553

548-
def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
554+
def create_pull_request(
555+
self, owner: str, repo_name: str, branch: str, commits: List[str]
556+
) -> bool:
549557
"""
550558
Create a pull request in `self.repo_name`. The base branch of the
551559
pull request will be chosen based on the the milestone attached to
@@ -567,9 +575,15 @@ def create_pull_request(self, owner: str, repo_name: str, branch: str) -> bool:
567575
print("PR already exists...")
568576
return True
569577
try:
578+
commit_message = repo.get_commit(commits[-1]).commit.message
579+
message_lines = commit_message.splitlines()
580+
title = "{}: {}".format(release_branch_for_issue, message_lines[0])
581+
body = "Backport {}\n\nRequested by: @{}".format(
582+
" ".join(commits), self.requested_by
583+
)
570584
pull = repo.create_pull(
571-
title=f"PR for {issue_ref}",
572-
body="resolves {}".format(issue_ref),
585+
title=title,
586+
body=body,
573587
base=release_branch_for_issue,
574588
head=head,
575589
maintainer_can_modify=False,
@@ -683,6 +697,12 @@ def execute_command(self) -> bool:
683697
"setup-llvmbot-git",
684698
help="Set the default user and email for the git repo in LLVM_PROJECT_DIR to llvmbot",
685699
)
700+
release_workflow_parser.add_argument(
701+
"--requested-by",
702+
type=str,
703+
required=True,
704+
help="The user that requested this backport",
705+
)
686706

687707
args = parser.parse_args()
688708

@@ -712,6 +732,7 @@ def execute_command(self) -> bool:
712732
args.branch_repo,
713733
args.branch_repo_token,
714734
args.llvm_project_dir,
735+
args.requested_by,
715736
)
716737
if not release_workflow.release_branch_for_issue:
717738
release_workflow.issue_notify_no_milestone(sys.stdin.readlines())

0 commit comments

Comments
 (0)