Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions .github/workflows/auto-update-pr-branches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,19 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'trebent/envparser'
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
- name: Generate Jeeves app token
id: jeeves-token
uses: actions/create-github-app-token@v1
with:
client-id: ${{ secrets.JEEVES_APP_ID }}
app-id: ${{ secrets.JEEVES_APP_ID }}
private-key: ${{ secrets.JEEVES_APP_PRIVATE_KEY }}

- name: Update out-of-date PR branches
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
GH_TOKEN: ${{ steps.jeeves-token.outputs.token }}
run: |
gh pr list --repo "${{ github.repository }}" --base main --state open --json number,author \
--jq '.[] | "\(.number) \(.author.login)"' | \
while IFS=' ' read -r pr author; do
echo "Checking PR #$pr (author: $author)..."
if [ "$author" = "app/dependabot" ]; then
# Trigger Dependabot to rebase its own branch rather than pushing directly with
# the Jeeves bot token. If Jeeves pushes, dependabot/fetch-metadata fails with
# "PR is not from Dependabot" on the resulting synchronize event, which prevents
# Jeeves from re-approving and re-enabling auto-merge on that PR.
merge_state=$(gh pr view "$pr" --repo "${{ github.repository }}" \
--json mergeStateStatus --jq '.mergeStateStatus' 2>/dev/null || echo "ERROR")
if [ "$merge_state" = "BEHIND" ]; then
echo "PR #$pr is behind main, triggering Dependabot rebase"
gh pr comment --repo "${{ github.repository }}" "$pr" --body "@dependabot rebase" || true
else
echo "PR #$pr merge state is '$merge_state', no update needed"
fi
else
gh pr update-branch --rebase --repo "${{ github.repository }}" "$pr" || true
fi
gh pr list --repo "${{ github.repository }}" --base main --state open --json number \
--jq '.[].number' | \
while read -r pr; do
echo "Updating PR #$pr..."
gh pr update-branch --rebase --repo "${{ github.repository }}" "$pr" || true
done