UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

51 lines 1.98 kB
import { graphql } from '../../../graphql/generated/index.js'; import { BackportError } from '../../backport-error.js'; import { graphqlRequest } from './client/graphql-client.js'; import { fetchPullRequestId } from './fetch-pull-request-id.js'; export async function enablePullRequestAutoMerge(options, targetPullRequestNumber) { const { githubToken, githubApiBaseUrlV4, autoMergeMethod = 'merge', } = options; const pullRequestId = await fetchPullRequestId(options, targetPullRequestNumber); const query = graphql(` mutation EnablePullRequestAutoMerge( $pullRequestId: ID! $mergeMethod: PullRequestMergeMethod! ) { enablePullRequestAutoMerge( input: { pullRequestId: $pullRequestId, mergeMethod: $mergeMethod } ) { pullRequest { number } } } `); const mergeMethodMap = { merge: 'MERGE', squash: 'SQUASH', rebase: 'REBASE', }; const variables = { pullRequestId, mergeMethod: mergeMethodMap[autoMergeMethod] ?? 'MERGE', }; const result = await graphqlRequest({ githubToken, githubApiBaseUrlV4 }, query, variables); if (result.error) { if (isMissingStatusChecksError(result)) { throw new BackportError({ code: 'auto-merge-not-available-exception', message: result.error.message, }); } throw new BackportError({ code: 'github-api-exception', message: result.error.message, }); } return result.data?.enablePullRequestAutoMerge?.pullRequest?.number; } function isMissingStatusChecksError(result) { return result.error?.graphQLErrors.some((e) => e.extensions.type === 'UNPROCESSABLE' && (e.message.includes('Branch does not have required protected branch rules') || e.message.includes('Pull request is in clean status'))); } //# sourceMappingURL=enable-pull-request-auto-merge.js.map