Skip to content

Commit 1159311

Browse files
committed
Add workflow to auto-update open PRs when main changes
Triggers on every push to main, loops through all open PRs targeting main, and merges the latest main into each branch via the GitHub API. PRs with conflicts are skipped with a clear log message. https://claude.ai/code/session_011MeXGRNe15ksjbwsDM8ULN
1 parent b844acc commit 1159311

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

.github/workflows/update-prs.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Update PRs with main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
update-prs:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
steps:
15+
- name: Update all open PRs with latest main
16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
run: |
19+
pr_numbers=$(gh pr list \
20+
--repo ${{ github.repository }} \
21+
--base main \
22+
--state open \
23+
--json number \
24+
--jq '.[].number')
25+
26+
if [ -z "$pr_numbers" ]; then
27+
echo "No open PRs to update."
28+
exit 0
29+
fi
30+
31+
for pr in $pr_numbers; do
32+
echo "Updating PR #$pr..."
33+
if gh api repos/${{ github.repository }}/pulls/$pr/update-branch \
34+
-X PUT \
35+
-H "Accept: application/vnd.github+json" > /dev/null 2>&1; then
36+
echo " ✓ PR #$pr updated"
37+
else
38+
echo " ✗ PR #$pr has conflicts or is already up to date — skipping"
39+
fi
40+
done

0 commit comments

Comments
 (0)