UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

43 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTargetPRLabels = void 0; const lodash_1 = require("lodash"); const filterEmpty_1 = require("../../utils/filterEmpty"); const getSourceBranchFromCommits_1 = require("../getSourceBranchFromCommits"); const logger_1 = require("../logger"); function getTargetPRLabels({ interactive, targetPRLabels, commits, targetBranch, }) { const labels = getLabels({ commits, targetBranch, targetPRLabels, interactive, }); return (0, lodash_1.uniq)(labels); } exports.getTargetPRLabels = getTargetPRLabels; function getLabels({ commits, targetBranch, targetPRLabels, interactive, }) { const sourceBranch = (0, getSourceBranchFromCommits_1.getSourceBranchFromCommits)(commits); const labels = commits .flatMap((c) => { const targetPullRequest = c.targetPullRequestStates.find((pr) => pr.branch === targetBranch); if (!targetPullRequest?.branchLabelMappingKey) { logger_1.logger.info('Missing branchLabelMappingKey for target pull request'); // remove dynamic labels like `$1` in interactive mode return targetPRLabels.filter((l) => { return l.match(/\$\d/) === null || !interactive; }); } const regex = new RegExp(targetPullRequest.branchLabelMappingKey); return targetPRLabels.map((targetPRLabel) => { return targetPullRequest.label?.replace(regex, targetPRLabel); }); }) .filter(filterEmpty_1.filterNil) .map((label) => { return label .replaceAll('{{targetBranch}}', targetBranch) .replaceAll('{{sourceBranch}}', sourceBranch); }); return labels; } //# sourceMappingURL=getTargetPRLabels.js.map