Skip to content

Commit 80a5912

Browse files
authored
Adding rebase-dependabot.yml (#24)
1 parent 8d729f4 commit 80a5912

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Rebase Dependabot
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
on:
12+
push:
13+
branches:
14+
- main
15+
workflow_dispatch:
16+
17+
jobs:
18+
rebase-dependabot:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Rebase Dependabot open PRs
22+
uses: actions/github-script@v6
23+
with:
24+
script: |
25+
const owner = context.repo.owner;
26+
const repo = context.repo.repo;
27+
// list open PRs
28+
const { data: prs } = await github.rest.pulls.list({
29+
owner, repo, state: "open", per_page: 100
30+
});
31+
32+
for (const pr of prs) {
33+
if (!pr.head.ref) {
34+
continue;
35+
}
36+
37+
// target dependabot PRs
38+
const isDependabot = pr.user && (
39+
pr.user.login === "dependabot[bot]" ||
40+
(pr.user.login.endsWith("[bot]") && pr.head.ref.startsWith("dependabot/"))
41+
);
42+
if (!isDependabot) continue;
43+
44+
try {
45+
await github.rest.pulls.updateBranch({
46+
owner,
47+
repo,
48+
pull_number: pr.number
49+
});
50+
core.info(`Requested update for PR #${pr.number}`);
51+
} catch (err) {
52+
core.warning(`Failed to update PR #${pr.number}: ${err.message}`);
53+
}
54+
}

0 commit comments

Comments
 (0)