UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

50 lines 2.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseConfigFile = exports.readConfigFile = void 0; const promises_1 = require("fs/promises"); const strip_json_comments_1 = __importDefault(require("strip-json-comments")); const BackportError_1 = require("../../lib/BackportError"); const excludeUndefined_1 = require("../../utils/excludeUndefined"); async function readConfigFile(filepath) { const fileContents = await (0, promises_1.readFile)(filepath, 'utf8'); try { return parseConfigFile(fileContents); } catch (e) { throw new BackportError_1.BackportError(`"${filepath}" contains invalid JSON:\n\n${fileContents}`); } } exports.readConfigFile = readConfigFile; // ensure backwards compatability when config options are renamed function parseConfigFile(fileContents) { const configWithoutComments = (0, strip_json_comments_1.default)(fileContents); const { upstream, labels, branches, addOriginalReviewers, ...config } = JSON.parse(configWithoutComments); const { repoName, repoOwner } = parseUpstream(upstream, config); return (0, excludeUndefined_1.excludeUndefined)({ ...config, // `branches` was renamed `targetBranchChoices` targetBranchChoices: config.targetBranchChoices ?? branches, // `upstream` has been renamed to `repoOwner`/`repoName` repoName, repoOwner, // `addOriginalReviewers` has been renamed to `copySourcePRReviewers` copySourcePRReviewers: config.copySourcePRReviewers ?? addOriginalReviewers, // `labels` was renamed `targetPRLabels` targetPRLabels: config.targetPRLabels ?? labels, }); } exports.parseConfigFile = parseConfigFile; function parseUpstream(upstream, config) { if (upstream) { const [repoOwner, repoName] = upstream.split('/'); return { repoOwner, repoName }; } return { repoOwner: config.repoOwner, repoName: config.repoName, }; } //# sourceMappingURL=readConfigFile.js.map