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 6432f50 commit 084badf
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions tools/auto-pick-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,35 @@

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

# Check if the commit is present in the new branch
commit_check = subprocess.run(
["git", "rev-list", "--count", f"{TARGET_BRANCH}..{new_branch_name}"],
["git", "rev-list", "--count", f"{merge_commit_sha}"],
cwd=repo_dir,
capture_output=True,
text=True
)
if int(commit_check.stdout.strip()) > 0:

if commit_check.returncode == 0 and 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
subprocess.run(["git", "push", "origin", new_branch_name], cwd=repo_dir, check=True)
print(f"Pushed new branch {new_branch_name} to origin.")

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

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()}")
print(f"Created a new PR #{new_pr.number} for cherry-picked changes.")
else:
print(f"No new commits to create a PR from {new_branch_name}.")
print(f"Commit {merge_commit_sha} was not found in {new_branch_name} after cherry-picking.")

except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError:
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 084badf

Please sign in to comment.