Change the cherry-pick PR's title to the commit's title, instead of the issue's title (#1832)
Replace the cherry-pick PR's title to last commit's title.
diff --git a/actions/cherry_picker/cherrypick_with_commits.py b/actions/cherry_picker/cherrypick_with_commits.py
index 7622d47..70ff3de 100644
--- a/actions/cherry_picker/cherrypick_with_commits.py
+++ b/actions/cherry_picker/cherrypick_with_commits.py
@@ -1,6 +1,6 @@
import os, re
from vars import input_data, upstream_repo, cherrypick_with_commits_infos
-from functions import cherry_pick, create_pr, issue_comment, get_pr_body, PushCpException, push_to_branch, get_middle_text
+from functions import cherry_pick, create_pr, issue_comment, get_pr_title_body, PushCpException, push_to_branch, get_middle_text
milestone_title = os.environ["INPUT_MILESTONE_TITLE"]
milestoned_issue_number = os.environ["INPUT_MILESTONED_ISSUE_NUMBER"]
@@ -32,7 +32,7 @@
for idx, commit_id in enumerate(issue_body_dict["commits"]):
try:
cherry_pick(commit_id, release_branch_name, target_branch_name, requires_clone, requires_checkout, input_data)
- msg_body = get_pr_body(commit_id, input_data["api_repo_name"])
+ msg_body = get_pr_title_body(commit_id, input_data["api_repo_name"])["body"]
success_msg = {"commit_id": commit_id, "msg": msg_body}
successful_commits.append(success_msg)
except PushCpException as pe:
diff --git a/actions/cherry_picker/cherrypick_with_milestones.py b/actions/cherry_picker/cherrypick_with_milestones.py
index 0c38919..cb4e587 100644
--- a/actions/cherry_picker/cherrypick_with_milestones.py
+++ b/actions/cherry_picker/cherrypick_with_milestones.py
@@ -1,5 +1,5 @@
import os, requests
-from functions import get_commit_id, get_reviewers, extract_release_numbers_data, cherry_pick, create_pr, get_labels, get_pr_body, issue_comment, push_to_branch
+from functions import get_commit_id, get_reviewers, extract_release_numbers_data, cherry_pick, create_pr, get_labels, get_pr_title_body, issue_comment, push_to_branch
from vars import headers, upstream_repo, input_data
triggered_on = os.environ["INPUT_TRIGGERED_ON"]
@@ -30,7 +30,7 @@
labels = get_labels(pr_number, input_data["api_repo_name"])
# Retrieve issue/PR's title and body
-pr_body = get_pr_body(commit_id, input_data["api_repo_name"])
+pr_title_body = get_pr_title_body(commit_id, input_data["api_repo_name"])
# Perform cherry-pick and then create a pr if it's successful.
requires_clone = True
@@ -39,7 +39,8 @@
release_branch_name = f"{input_data['release_branch_name_initials']}{release_number}"
target_branch_name = f"cp{pr_number}-{release_number}"
issue_number = release_numbers_data[k]
- pr_title = issue_data["title"]
+ pr_title = pr_title_body["title"]
+ pr_body = pr_title_body["body"]
try:
cherry_pick(commit_id, release_branch_name, target_branch_name, requires_clone, True, input_data)
push_to_branch(target_branch_name)
diff --git a/actions/cherry_picker/functions.py b/actions/cherry_picker/functions.py
index fb10f4a..afe2748 100644
--- a/actions/cherry_picker/functions.py
+++ b/actions/cherry_picker/functions.py
@@ -95,7 +95,7 @@
subprocess.run(['git', 'branch', release_branch_name, f"upstream/{release_branch_name}"])
release_push_status = subprocess.run(['git', 'push', '--set-upstream', 'origin', release_branch_name])
if release_push_status.returncode != 0:
- raise Exception(f"Could not create and push the branch, {release_branch_name}")
+ raise Exception(f"The branch, {release_branch_name}, may not exist. Please retry the cherry-pick after the branch is created.")
subprocess.run(['git', 'remote', 'rm', 'upstream'])
subprocess.run(['git', 'checkout', release_branch_name])
status_checkout_target = subprocess.run(['git', 'checkout', '-b', target_branch_name])
@@ -145,9 +145,10 @@
if "awaiting-review" not in labels_list: labels_list.append("awaiting-review")
return labels_list
-def get_pr_body(commit_id, api_repo_name):
+def get_pr_title_body(commit_id, api_repo_name):
response_commit = requests.get(f"https://api.github.com/repos/{api_repo_name}/commits/{commit_id}")
original_msg = response_commit.json()["commit"]["message"]
+ pr_title = original_msg[:original_msg.index("\n\n")] if "\n\n" in original_msg else original_msg
pr_body = original_msg[original_msg.index("\n\n") + 2:] if "\n\n" in original_msg else original_msg
commit_str_body = f"Commit https://github.com/{api_repo_name}/commit/{commit_id}"
if "PiperOrigin-RevId" in pr_body:
@@ -155,7 +156,7 @@
pr_body = pr_body[:piper_index] + f"{commit_str_body}\n\n" + pr_body[piper_index:]
else:
pr_body += f"\n\n{commit_str_body}"
- return pr_body
+ return {"title": pr_title, "body": pr_body}
def get_middle_text(all_str, left_str, right_str):
left_index = all_str.index(left_str) + len(left_str)