-
Notifications
You must be signed in to change notification settings - Fork 1k
59 lines (54 loc) · 2.04 KB
/
Copy pathdependabotautomerge.yml
File metadata and controls
59 lines (54 loc) · 2.04 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
51
52
53
54
55
56
57
58
59
name: Dependabot auto-merge
on:
pull_request_target:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch:
schedule:
- cron: '17 * * * *'
permissions:
contents: write
pull-requests: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]' && github.event.pull_request.draft == false }}
steps:
- name: Enable auto-merge for Dependabot PRs
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: merge
dependabot-backfill:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request_target' }}
steps:
- name: Enable auto-merge on all open Dependabot PRs
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const {owner, repo} = context.repo;
const pulls = await github.paginate(github.rest.pulls.list, {
owner,
repo,
state: 'open',
per_page: 100
});
const dependabotPRs = pulls.filter((pr) => pr.user?.login === 'dependabot[bot]' && !pr.draft);
core.info(`Found ${dependabotPRs.length} open Dependabot PR(s).`);
for (const pr of dependabotPRs) {
try {
await github.graphql(
`mutation EnableAutoMerge($pullRequestId: ID!) {
enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, mergeMethod: MERGE}) {
pullRequest { number }
}
}`,
{ pullRequestId: pr.node_id }
);
core.info(`Enabled auto-merge for #${pr.number}`);
} catch (error) {
core.warning(`Could not enable auto-merge for #${pr.number}: ${error.message}`);
}
}