UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

63 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fetchExistingPullRequest = void 0; const lodash_1 = require("lodash"); const generated_1 = require("../../../graphql/generated"); const graphqlClient_1 = require("./client/graphqlClient"); async function fetchExistingPullRequest({ options, prPayload, }) { const { githubApiBaseUrlV4, accessToken } = options; const query = (0, generated_1.graphql)(` query ExistingPullRequest( $repoOwner: String! $repoName: String! $base: String! $head: String! ) { repository(owner: $repoOwner, name: $repoName) { name ref(qualifiedName: $head) { name associatedPullRequests( first: 1 states: OPEN baseRefName: $base headRefName: $head ) { edges { node { number url } } } } } } `); const { repoForkOwner, head } = splitHead(prPayload); const variables = { repoOwner: repoForkOwner, repoName: prPayload.repo, base: prPayload.base, head: head, }; const client = (0, graphqlClient_1.getGraphQLClient)({ accessToken, githubApiBaseUrlV4 }); const result = await client.query(query, variables); if (result.error) { throw new graphqlClient_1.GithubV4Exception(result); } const existingPullRequest = (0, lodash_1.first)(result.data?.repository?.ref?.associatedPullRequests.edges); if (!existingPullRequest?.node) { return; } return { url: existingPullRequest.node.url, number: existingPullRequest.node.number, }; } exports.fetchExistingPullRequest = fetchExistingPullRequest; function splitHead(prPayload) { const [repoForkOwner, head] = prPayload.head.split(':'); return { repoForkOwner, head }; } //# sourceMappingURL=fetchExistingPullRequest.js.map