Skip to content

Commit 504193f

Browse files
authored
Use official auto-merge for repo-sync PRs (attempt #2) (github#18628)
* Add github-script step to enable GitHub's official auto-merge on repo-sync PRs * Reenable automerge action via label and fail gracefully if official auto-merge enablement fails
1 parent 8af652f commit 504193f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/workflows/repo-sync.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@ jobs:
163163
console.log(`Branch is already up-to-date`)
164164
}
165165
166+
- name: Enable GitHub auto-merge
167+
if: ${{ steps.find-pull-request.outputs.number }}
168+
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
169+
with:
170+
github-token: ${{ secrets.GITHUB_TOKEN }}
171+
script: |
172+
const pull = await github.pulls.get({
173+
...context.repo,
174+
pull_number: parseInt(${{ steps.find-pull-request.outputs.number }})
175+
})
176+
const pullNodeId = pull.data.node_id
177+
console.log(`Pull request GraphQL Node ID: ${pullNodeId}`)
178+
const mutation = `mutation ($id: ID!) {
179+
enablePullRequestAutoMerge(input: {
180+
pullRequestId: $id,
181+
mergeMethod: MERGE
182+
}) {
183+
clientMutationId
184+
}
185+
}`
186+
const variables = {
187+
id: pullNodeId
188+
}
189+
const graph = await github.graphql(mutation, variables)
190+
if (graph.errors && graph.errors.length > 0) {
191+
console.error('ERROR! Failed to enable auto-merge:\n - ', graph.errors.map(error => error.message).join('\n - '))
192+
} else {
193+
console.log('Auto-merge enabled!')
194+
}
195+
166196
- name: Send Slack notification if workflow fails
167197
uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
168198
if: failure()

0 commit comments

Comments
 (0)