Skip to content

Commit c2583f3

Browse files
authored
use default dependabot template with some tweaks (#12861)
1 parent 3dd5b99 commit c2583f3

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed
+19-35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
name: Dependabot auto-merge
22
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
612

713
permissions:
814
pull-requests: write
@@ -11,15 +17,17 @@ permissions:
1117
jobs:
1218
dependabot:
1319
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')
1523
steps:
1624
- name: Dependabot metadata
17-
id: dependabot-metadata
25+
id: metadata
1826
uses: dependabot/fetch-metadata@v2
1927
with:
2028
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' }}
2331
uses: actions/github-script@v7
2432
with:
2533
github-token: '${{ secrets.GITHUB_TOKEN }}'
@@ -31,11 +39,13 @@ jobs:
3139
}
3240
}
3341
}`
42+
3443
const repoInfo = {
3544
owner: context.repo.owner,
3645
repo: context.repo.repo,
3746
pullRequestNumber: context.issue.number,
3847
}
48+
3949
const response = await github.graphql(getPullRequestIdQuery, repoInfo)
4050
4151
await github.rest.pulls.createReview({
@@ -60,40 +70,14 @@ jobs:
6070
}
6171
}
6272
}`
73+
6374
const data = {
6475
pullRequestId: response.repository.pullRequest.id,
6576
mergeMethod: 'SQUASH',
6677
}
6778
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-
9479
try {
9580
await github.graphql(enableAutoMergeQuery, data)
9681
} 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)
9983
}

0 commit comments

Comments
 (0)