-
Notifications
You must be signed in to change notification settings - Fork 2
50 lines (41 loc) · 1.44 KB
/
dependabot-automerge.yml
File metadata and controls
50 lines (41 loc) · 1.44 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: dependabot-automerge
on:
workflow_run:
workflows: ["build"]
types: [completed]
permissions:
contents: write
pull-requests: write
jobs:
automerge:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Merge Dependabot PR if eligible
uses: actions/github-script@v7
with:
script: |
const prs = context.payload.workflow_run.pull_requests;
if (!prs || prs.length === 0) {
core.info('No pull requests associated with this workflow_run.');
return;
}
const prNumber = prs[0].number;
const { owner, repo } = context.repo;
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: prNumber });
const author = pr.user?.login || '';
if (author !== 'dependabot[bot]' && author !== 'dependabot') {
core.info(`PR #${prNumber} is not from Dependabot (${author}).`);
return;
}
if (pr.mergeable_state !== 'clean') {
core.info(`PR #${prNumber} is not mergeable yet (state: ${pr.mergeable_state}).`);
return;
}
await github.rest.pulls.merge({
owner,
repo,
pull_number: prNumber,
merge_method: 'merge'
});
core.info(`Merged Dependabot PR #${prNumber}.`);