From 1e0f4618e2092e1c698c5619fb12d65747cc5a47 Mon Sep 17 00:00:00 2001 From: Kyle Durand Date: Fri, 1 Nov 2024 11:35:33 -0400 Subject: [PATCH] =?UTF-8?q?dependabot=20auto=20merge=20fix:=20use=20squash?= =?UTF-8?q?=20instead=20of=20merge,=20check=20status=20=E2=80=A6=20(#12859?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use squash instead of merge, check status first to avoid unstable status, add error logging --- .github/workflows/dependabot-auto-merge.yml | 35 +++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 9567b8f0e86..67a470b6b84 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -59,7 +59,38 @@ jobs: }` const data = { pullRequestId: response.repository.pullRequest.id, - mergeMethod: 'MERGE', + mergeMethod: 'SQUASH', } - await github.graphql(enableAutoMergeQuery, data) + const checkStatusQuery = `query($owner: String!, $repo: String!, $pullRequestNumber: Int!) { + repository(owner: $owner, name: $repo) { + pullRequest(number: $pullRequestNumber) { + commits(last: 1) { + nodes { + commit { + statusCheckRollup { + state + } + } + } + } + } + } + }` + + // Check if status checks are successful + const statusResponse = await github.graphql(checkStatusQuery, repoInfo) + const checkState = statusResponse.repository.pullRequest.commits.nodes[0]?.commit?.statusCheckRollup?.state + + if (checkState !== 'SUCCESS') { + console.log('Status checks are not successful yet. Current state:', checkState) + core.setFailed('Status checks must pass before enabling auto-merge') + return + } + + try { + await github.graphql(enableAutoMergeQuery, data) + } catch (error) { + console.log('Failed to enable auto-merge:', error.message) + core.setFailed(error.message) + }