UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

57 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRepoOwnerAndNameFromGitRemotes = void 0; const generated_1 = require("../../../graphql/generated"); const maybe_1 = require("../../../utils/maybe"); const git_1 = require("../../git"); const logger_1 = require("../../logger"); const graphqlClient_1 = require("./client/graphqlClient"); // This method should be used to get the origin owner (instead of a fork owner) async function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrlV4, cwd, }) { const remotes = await (0, git_1.getRepoInfoFromGitRemotes)({ cwd }); const firstRemote = (0, maybe_1.maybe)(remotes[0]); if (!firstRemote) { return {}; } try { const variables = { repoOwner: firstRemote.repoOwner, repoName: firstRemote.repoName, }; const query = (0, generated_1.graphql)(` query RepoOwnerAndName($repoOwner: String!, $repoName: String!) { repository(owner: $repoOwner, name: $repoName) { isFork name owner { login } parent { owner { login } } } } `); 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 repo = result.data?.repository; return { repoName: repo?.name, repoOwner: repo?.isFork ? repo.parent?.owner.login : repo?.owner.login, // get the original owner (not the fork owner) }; } catch (e) { if (e instanceof graphqlClient_1.GithubV4Exception) { logger_1.logger.error(e.message); return {}; } throw e; } } exports.getRepoOwnerAndNameFromGitRemotes = getRepoOwnerAndNameFromGitRemotes; //# sourceMappingURL=getRepoOwnerAndNameFromGitRemotes.js.map