backport
Version:
A CLI tool that automates the process of backporting commits
34 lines • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTitle = void 0;
const handlebars_1 = __importDefault(require("handlebars"));
const getSourceBranchFromCommits_1 = require("../../../getSourceBranchFromCommits");
const logger_1 = require("../../../logger");
const commitFormatters_1 = require("../../commitFormatters");
function getTitle({ options, commits, targetBranch, }) {
const sourceBranch = (0, getSourceBranchFromCommits_1.getSourceBranchFromCommits)(commits);
const commitMessages = commits
.map((c) => (0, commitFormatters_1.getFirstLine)(c.sourceCommit.message))
.join(' | ');
const defaultPrTitle = '[{{targetBranch}}] {{commitMessages}}';
const prTitle = (options.prTitle ?? defaultPrTitle)
.replaceAll('{{commitMessages}}', `{{{{raw}}}}${commitMessages}{{{{/raw}}}}`)
.replaceAll('{{targetBranch}}', targetBranch)
.replaceAll('{{sourceBranch}}', sourceBranch);
try {
const template = handlebars_1.default.compile(prTitle, { noEscape: true });
return template({
sourcePullRequest: commits[0].sourcePullRequest, // assume that all commits are from the same PR
commits,
});
}
catch (error) {
logger_1.logger.error('Error while compiling PR title template', error);
return prTitle.replaceAll('{{{{raw}}}}', '').replaceAll('{{{{/raw}}}}', '');
}
}
exports.getTitle = getTitle;
//# sourceMappingURL=getTitle.js.map