backport
Version:
A CLI tool that automates the process of backporting commits
33 lines • 1.64 kB
JavaScript
import { filterNil } from '../../../utils/filter-empty.js';
import { getSourceBranchFromCommits } from '../../get-source-branch-from-commits.js';
import { logger } from '../../logger.js';
// Resolve labels defined in configuration (`targetPRLabels`) into their concrete
// values for the current target branch. This includes expanding regex captures,
// replacing template placeholders and skipping dynamic labels when we lack
// branch mapping context in interactive mode.
export function getConfiguredTargetPRLabels({ commits, targetBranch, targetPRLabels, interactive, }) {
const sourceBranch = getSourceBranchFromCommits(commits);
const labels = commits
.flatMap((c) => {
const targetPullRequest = c.targetPullRequestStates.find((pr) => pr.branch === targetBranch);
if (!targetPullRequest?.branchLabelMappingKey) {
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(filterNil)
.map((label) => {
return label
.replaceAll('{{targetBranch}}', targetBranch)
.replaceAll('{{sourceBranch}}', sourceBranch);
});
return labels;
}
//# sourceMappingURL=get-configured-target-pr-labels.js.map