1
0
mirror of synced 2025-12-30 03:01:36 -05:00
Files
docs/.github/actions-scripts/enable-automerge.js
Peter Bengtsson e2ec55c7d8 use shorthand to calm codeql warnings (#27882)
* use shorthand to calm codeql warnings

* there was more
2022-05-21 18:50:56 +00:00

51 lines
1.3 KiB
JavaScript

import { getOctokit } from '@actions/github'
main()
async function main() {
const [org, repo] = process.env.GITHUB_REPOSITORY.split('/')
if (!org || !repo) {
throw new Error('GITHUB_REPOSITORY environment variable not set')
}
const prNumber = process.env.AUTOMERGE_PR_NUMBER
if (!prNumber) {
throw new Error(`AUTOMERGE_PR_NUMBER environment variable not set`)
}
const token = process.env.GITHUB_TOKEN
if (!token) {
throw new Error(`GITHUB_TOKEN environment variable not set`)
}
const github = getOctokit(token)
const pull = await github.rest.pulls.get({
owner: org,
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!')
}
}