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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/issue-release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 25 additions & 4 deletions llvm/utils/git/github-automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -567,9 +575,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...

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,
Expand Down Expand Up @@ -679,6 +693,12 @@ 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()

Expand Down Expand Up @@ -708,6 +728,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())
Expand Down