Skip to content

Commit

Permalink
Use official auto-merge for repo-sync PRs (attempt #2) (github#18628)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JamesMGreene authored Apr 12, 2021
1 parent 8af652f commit 504193f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/repo-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,36 @@ jobs:
console.log(`Branch is already up-to-date`)
}
- name: Enable GitHub auto-merge
if: ${{ steps.find-pull-request.outputs.number }}
uses: actions/github-script@626af12fe9a53dc2972b48385e7fe7dec79145c9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pull = await github.pulls.get({
...context.repo,
pull_number: parseInt(${{ steps.find-pull-request.outputs.number }})
})
const pullNodeId = pull.data.node_id
console.log(`Pull request GraphQL Node ID: ${pullNodeId}`)
const mutation = `mutation ($id: ID!) {
enablePullRequestAutoMerge(input: {
pullRequestId: $id,
mergeMethod: MERGE
}) {
clientMutationId
}
}`
const variables = {
id: pullNodeId
}
const graph = await github.graphql(mutation, variables)
if (graph.errors && graph.errors.length > 0) {
console.error('ERROR! Failed to enable auto-merge:\n - ', graph.errors.map(error => error.message).join('\n - '))
} else {
console.log('Auto-merge enabled!')
}
- name: Send Slack notification if workflow fails
uses: someimportantcompany/github-actions-slack-message@0b470c14b39da4260ed9e3f9a4f1298a74ccdefd
if: failure()
Expand Down

0 comments on commit 504193f

Please sign in to comment.