-
Notifications
You must be signed in to change notification settings - Fork 1
50 lines (44 loc) · 1.59 KB
/
auto-update-prs.yml
File metadata and controls
50 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Auto-update PRs on base branch push
on:
push:
branches: [main]
concurrency:
group: auto-update-prs
cancel-in-progress: true
jobs:
auto-update:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Update open PRs targeting main
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const { data: prs } = await github.rest.pulls.list({
owner, repo, base: 'main', state: 'open', per_page: 100,
});
console.log(`Found ${prs.length} open PR(s) targeting main`);
let updated = 0;
for (const pr of prs) {
if (pr.head.repo?.full_name !== `${owner}/${repo}`) {
console.log(`Skipping PR #${pr.number} (fork): ${pr.title}`);
continue;
}
try {
await github.rest.pulls.updateBranch({ owner, repo, pull_number: pr.number });
console.log(`✓ Updated PR #${pr.number}: ${pr.title}`);
updated++;
} catch (e) {
if (e.status === 422 || e.message?.toLowerCase().includes('already up to date')) {
console.log(` PR #${pr.number} already up to date`);
} else {
console.error(`✗ PR #${pr.number} failed: ${e.message}`);
}
}
}
console.log(`Done: ${updated} updated.`);