1
1
name : Dependabot auto-merge
2
2
on :
3
- pull_request :
4
- check_suite :
5
- types : [completed]
3
+ pull_request_target :
4
+ types :
5
+ - opened
6
+ - synchronize
7
+
8
+ workflow_run :
9
+ workflows : ['*']
10
+ types :
11
+ - completed
6
12
7
13
permissions :
8
14
pull-requests : write
@@ -11,15 +17,17 @@ permissions:
11
17
jobs :
12
18
dependabot :
13
19
runs-on : ubuntu-latest
14
- if : ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
20
+ if : |
21
+ github.event.pull_request.user.login == 'dependabot[bot]' &&
22
+ (github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'neutral')
15
23
steps :
16
24
- name : Dependabot metadata
17
- id : dependabot- metadata
25
+ id : metadata
18
26
uses : dependabot/fetch-metadata@v2
19
27
with :
20
28
github-token : ' ${{ secrets.GITHUB_TOKEN }}'
21
- - name : Approve and /shipit Dependabot PRs for patch and minor versions
22
- if : ${{ steps.dependabot- metadata.outputs.update-type != 'version-update:semver-major' }}
29
+ - name : Enable auto-merge for Dependabot PRs
30
+ if : ${{ steps.metadata.outputs.update-type != 'version-update:semver-major' }}
23
31
uses : actions/github-script@v7
24
32
with :
25
33
github-token : ' ${{ secrets.GITHUB_TOKEN }}'
@@ -31,11 +39,13 @@ jobs:
31
39
}
32
40
}
33
41
}`
42
+
34
43
const repoInfo = {
35
44
owner: context.repo.owner,
36
45
repo: context.repo.repo,
37
46
pullRequestNumber: context.issue.number,
38
47
}
48
+
39
49
const response = await github.graphql(getPullRequestIdQuery, repoInfo)
40
50
41
51
await github.rest.pulls.createReview({
@@ -60,40 +70,14 @@ jobs:
60
70
}
61
71
}
62
72
}`
73
+
63
74
const data = {
64
75
pullRequestId: response.repository.pullRequest.id,
65
76
mergeMethod: 'SQUASH',
66
77
}
67
78
68
- const checkStatusQuery = `query($owner: String!, $repo: String!, $pullRequestNumber: Int!) {
69
- repository(owner: $owner, name: $repo) {
70
- pullRequest(number: $pullRequestNumber) {
71
- commits(last: 1) {
72
- nodes {
73
- commit {
74
- statusCheckRollup {
75
- state
76
- }
77
- }
78
- }
79
- }
80
- }
81
- }
82
- }`
83
-
84
- // Check if status checks are successful
85
- const statusResponse = await github.graphql(checkStatusQuery, repoInfo)
86
- const checkState = statusResponse.repository.pullRequest.commits.nodes[0]?.commit?.statusCheckRollup?.state
87
-
88
- if (checkState === 'FAILURE' || checkState === 'ERROR') {
89
- console.log('Status checks failed. Current state:', checkState)
90
- core.setFailed('Status checks must pass before enabling auto-merge')
91
- return
92
- }
93
-
94
79
try {
95
80
await github.graphql(enableAutoMergeQuery, data)
96
81
} catch (error) {
97
- console.log('Failed to enable auto-merge:', error.message)
98
- core.setFailed(error.message)
82
+ console.error('Error enabling auto-merge:', error)
99
83
}
0 commit comments