Skip to content
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

More fixes for the backport script #7770

Merged
merged 15 commits into from
Feb 21, 2025
Merged
14 changes: 8 additions & 6 deletions .github/workflows/backport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ on:
# The workflow needs the permission to push branches
permissions:
contents: write
pull-requests: write
issues: write
actions: write
statuses: write

jobs:
backport:
name: Backport Bug Fixes
runs-on: ubuntu-latest

steps:
- name: Install Linux Dependencies
run: |
sudo apt-get update
sudo apt-get install pip

- name: Install Python Dependencies
run: |
pip install PyGithub requests
Expand All @@ -42,4 +41,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.ORG_AUTOMATION_TOKEN }}
run: |
git remote --verbose
scripts/backport.py

scripts/backport.py 2>&1

git remote --verbose
10 changes: 4 additions & 6 deletions scripts/backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def report_backport_not_done(original_pr, reason, details=None):
target_remote = "backport-target-remote"
git_returncode(f"remote remove {target_remote}")
git_check(
f'remote add {target_remote} https://{os.environ["GITHUB_TOKEN"]}@github.com/{token_user.login}/{source_repo.name}.git'
f'remote add {target_remote} https://{os.environ["GITHUB_TOKEN"]}@github.com/{source_repo.owner.login}/{source_repo.name}.git'
)

# Fetch all branches from the target repository, because we use the presence
Expand All @@ -436,8 +436,6 @@ def report_backport_not_done(original_pr, reason, details=None):

original_pr = pr_info.pygithub_pr
backport_branch = f"backport/{backport_target}/{original_pr.number}"
# We're creating the backport PR from the token user's fork.
backport_pr_head = f"{token_user.login}:{backport_branch}"

# If there is already a backport branch for this PR, this probably means
# that we already created the backport PR. Update it, because the PR might
Expand Down Expand Up @@ -467,7 +465,7 @@ def report_backport_not_done(original_pr, reason, details=None):
# Use merge and no force-push, so that the simultaneous changes made by
# other users are not accidentally overwritten.
git_check(f"merge --quiet --no-edit {source_remote}/{backport_target}")
git_check(f"push --quiet {target_remote} @:{backport_branch}")
git_check(f"push {target_remote} @:{backport_branch}")
continue

# Try to cherry-pick the commits.
Expand Down Expand Up @@ -509,7 +507,7 @@ def report_backport_not_done(original_pr, reason, details=None):
)

# Push the backport branch.
git_check(f"push --quiet {target_remote} @:refs/heads/{backport_branch}")
git_check(f"push {target_remote} @:refs/heads/{backport_branch}")

# Prepare description for the backport PR.
backport_description = (
Expand Down Expand Up @@ -572,7 +570,7 @@ def report_backport_not_done(original_pr, reason, details=None):
title=f"Backport to {backport_target}: #{original_pr.number}: {original_pr.title}",
body=backport_description,
# We're creating PR from the token user's fork.
head=backport_pr_head,
head=backport_branch,
base=backport_target,
)
backport_pr.add_to_labels("is-auto-backport")
Expand Down
Loading