UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

40 lines 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateTargetBranch = void 0; const generated_1 = require("../../../graphql/generated"); const BackportError_1 = require("../../BackportError"); const ora_1 = require("../../ora"); const graphqlClient_1 = require("./client/graphqlClient"); async function validateTargetBranch({ accessToken, repoName, repoOwner, branchName, githubApiBaseUrlV4 = 'https://api.github.com/graphql', interactive, }) { const query = (0, generated_1.graphql)(` query GetBranchId( $repoOwner: String! $repoName: String! $branchName: String! ) { repository(owner: $repoOwner, name: $repoName) { ref(qualifiedName: $branchName) { id } } } `); const spinner = (0, ora_1.ora)(interactive, '').start(); const variables = { repoOwner, repoName, branchName }; const client = (0, graphqlClient_1.getGraphQLClient)({ accessToken, githubApiBaseUrlV4 }); const result = await client.query(query, variables); if (result.error) { throw new graphqlClient_1.GithubV4Exception(result); } if (!result.data?.repository?.ref) { spinner.fail(`The branch "${branchName}" does not exist`); throw new BackportError_1.BackportError({ code: 'invalid-branch-exception', branchName: branchName, }); } spinner.stop(); return; } exports.validateTargetBranch = validateTargetBranch; //# sourceMappingURL=validateTargetBranch.js.map