1
0
mirror of synced 2026-01-07 09:01:31 -05:00
Files
docs/.github/actions-scripts/enable-automerge.js
2021-11-18 09:47:46 -08:00

40 lines
999 B
JavaScript

import { getOctokit } from '@actions/github'
const token = process.env.GITHUB_TOKEN
const prNumber = process.env.AUTOMERGE_PR_NUMBER
const github = getOctokit(token)
main()
async function main() {
const pull = await github.pulls.get({
...context.repo,
pull_number: parseInt(prNumber),
})
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)
console.log('GraphQL mutation result:\n' + JSON.stringify(graph))
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!')
}
}