Skip to content

Merge pull request #1168 from lorbax/fix-rust-toolchain-version-in-sc… #19

Merge pull request #1168 from lorbax/fix-rust-toolchain-version-in-sc…

Merge pull request #1168 from lorbax/fix-rust-toolchain-version-in-sc… #19

Workflow file for this run

name: Auto Rebase
on:
push:
branches:
- main
workflow_dispatch:
jobs:
rebase-outdated-prs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0 # Fetch full history to have the entire commit history
- name: Fetch open pull requests with label
run: |
gh auth setup-git
gh pr list --state open --label "ready-to-be-merged" --json number,headRepositoryOwner,headRefName --jq '.[] | "\(.number) \(.headRepositoryOwner.login) \(.headRefName)"' > pr_details.txt
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
- name: Rebase pull requests
run: |
while read pr_number pr_owner pr_branch; do
echo "Processing PR #$pr_number"
# Add the contributor's fork as a remote
git remote add contributor https://github.com/$pr_owner/$(gh repo view --json name -q '.name').git
# Fetch the contributor's branches
git fetch contributor
# Create a unique branch name for this PR
unique_branch_name="contributor-branch-$pr_number"
# Checkout the branch from the contributor's fork
git checkout -b $unique_branch_name contributor/$pr_branch
# Set the committer name and email to match the PR author
PR_AUTHOR_NAME=$(gh pr view $pr_number --json author --jq '.author.login')
PR_AUTHOR_EMAIL="${PR_AUTHOR_NAME}@users.noreply.github.com"
git config --global user.name "$PR_AUTHOR_NAME"
git config --global user.email "$PR_AUTHOR_EMAIL"
# Rebase the branch on top of the main branch
git fetch origin main
if ! git rebase origin/main; then
echo "Conflict detected. Aborting rebase and continuing."
git rebase --abort
# Post a comment on the PR to notify the author about the conflict
gh pr comment $pr_number --body "Hey @$PR_AUTHOR_NAME, your PR cannot be rebased due to conflicts. Could you resolve them, please?"
continue
fi
# Push the rebased branch back to the contributor's fork
git push --force-with-lease contributor $unique_branch_name:$pr_branch
# Remove the remote
git remote remove contributor
# Ensure we are not on the branch to be deleted
git checkout main
# Delete the local unique branch
git branch -D $unique_branch_name
done < pr_details.txt
env:
GITHUB_TOKEN: ${{ secrets.PAT }}