Skip to content

Commit

Permalink
Update auto-pick-script.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKirs authored Oct 24, 2024
1 parent 99650db commit 9f3239f
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions tools/auto-pick-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,49 @@

# Execute the cherry-pick operation
try:
result = subprocess.run(["git", "cherry-pick", merge_commit_sha], cwd=repo_dir, check=True)
result = subprocess.run(
["git", "cherry-pick", merge_commit_sha],
cwd=repo_dir,
check=True,
capture_output=True,
text=True
)
print(f"Successfully cherry-picked commit {merge_commit_sha} into {new_branch_name}.")

# Push the new branch
subprocess.run(["git", "push", "origin", new_branch_name], cwd=repo_dir)

# Create a new PR for the cherry-picked changes
new_pr = repo.create_pull(
title=f"Auto-pick PR #{pr.number} into {TARGET_BRANCH}",
body=f"Cherry-pick of commits from PR #{pr.number} into {TARGET_BRANCH}.",
head=new_branch_name,
base=TARGET_BRANCH

# Check for new commits
commit_check = subprocess.run(
["git", "rev-list", "--count", f"{TARGET_BRANCH}..{new_branch_name}"],
cwd=repo_dir,
capture_output=True,
text=True
)
print(f"Created a new PR #{new_pr.number} for cherry-picked changes.")
except subprocess.CalledProcessError:

if int(commit_check.stdout.strip()) > 0:
# Push the new branch
push_result = subprocess.run(
["git", "push", "origin", new_branch_name],
cwd=repo_dir,
capture_output=True,
text=True
)

if push_result.returncode == 0:
# Create a new PR for the cherry-picked changes
new_pr = repo.create_pull(
title=f"Auto-pick PR #{pr.number} into {TARGET_BRANCH}",
body=f"Cherry-pick of commits from PR #{pr.number} into {TARGET_BRANCH}.",
head=new_branch_name,
base=TARGET_BRANCH
)
print(f"Created a new PR #{new_pr.number} for cherry-picked changes.")
else:
print(f"Failed to push the new branch: {push_result.stderr.strip()}")
else:
print(f"No new commits to create a PR from {new_branch_name}.")

except subprocess.CalledProcessError as e:
print(f"Conflict occurred while cherry-picking commit {merge_commit_sha}.")
print(f"Cherry-pick error: {e.stderr.strip()}")
# Add conflict label
pr.add_to_labels(CONFLICT_LABEL)
print(f"Added label '{CONFLICT_LABEL}' to PR #{pr.number} due to conflict.")

0 comments on commit 9f3239f

Please sign in to comment.