Skip to content

Commit 1e0f461

Browse files
authored
dependabot auto merge fix: use squash instead of merge, check status … (#12859)
Use squash instead of merge, check status first to avoid unstable status, add error logging
1 parent f1e3d3d commit 1e0f461

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

.github/workflows/dependabot-auto-merge.yml

+33-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,38 @@ jobs:
5959
}`
6060
const data = {
6161
pullRequestId: response.repository.pullRequest.id,
62-
mergeMethod: 'MERGE',
62+
mergeMethod: 'SQUASH',
6363
}
6464
65-
await github.graphql(enableAutoMergeQuery, data)
65+
const checkStatusQuery = `query($owner: String!, $repo: String!, $pullRequestNumber: Int!) {
66+
repository(owner: $owner, name: $repo) {
67+
pullRequest(number: $pullRequestNumber) {
68+
commits(last: 1) {
69+
nodes {
70+
commit {
71+
statusCheckRollup {
72+
state
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}`
80+
81+
// Check if status checks are successful
82+
const statusResponse = await github.graphql(checkStatusQuery, repoInfo)
83+
const checkState = statusResponse.repository.pullRequest.commits.nodes[0]?.commit?.statusCheckRollup?.state
84+
85+
if (checkState !== 'SUCCESS') {
86+
console.log('Status checks are not successful yet. Current state:', checkState)
87+
core.setFailed('Status checks must pass before enabling auto-merge')
88+
return
89+
}
90+
91+
try {
92+
await github.graphql(enableAutoMergeQuery, data)
93+
} catch (error) {
94+
console.log('Failed to enable auto-merge:', error.message)
95+
core.setFailed(error.message)
96+
}

0 commit comments

Comments
 (0)