Skip to content

Commit 4d16f61

Browse files
committed
Automatically update PR branches
1 parent cf64356 commit 4d16f61

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

.github/workflows/update-prs.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Update PRs
3+
4+
on:
5+
push:
6+
workflow_dispatch:
7+
8+
permissions:
9+
pull-requests: write
10+
contents: write
11+
12+
jobs:
13+
update:
14+
if: startsWith(github.ref, 'refs/heads/')
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Update Pull Requests
18+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
19+
with:
20+
script: |
21+
const opts = github.rest.pulls.list.endpoint.merge({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
state: 'open',
25+
base: context.ref.replace('refs/heads/', ''),
26+
})
27+
const prs = await github.paginate(opts)
28+
for (const pr of prs) {
29+
core.info(`Updating PR #${pr.number}`)
30+
github.rest.pulls.updateBranch({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
pull_number: pr.number,
34+
}).then(function(result) {
35+
core.info(JSON.stringify(result.data))
36+
}).catch(function(error) {
37+
core.error(error)
38+
})
39+
}

0 commit comments

Comments
 (0)