UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

27 lines 1.27 kB
import Handlebars from 'handlebars'; import { getSourceBranchFromCommits } from '../../../get-source-branch-from-commits.js'; import { logger } from '../../../logger.js'; import { getFirstLine } from '../../commit-formatters.js'; export function getTitle({ options, commits, targetBranch, }) { const sourceBranch = getSourceBranchFromCommits(commits); const commitMessages = commits .map((c) => 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.compile(prTitle, { noEscape: true }); return template({ sourcePullRequest: commits.at(0)?.sourcePullRequest, // assume that all commits are from the same PR commits, }); } catch (error) { logger.error('Error while compiling PR title template', error); return prTitle.replaceAll('{{{{raw}}}}', '').replaceAll('{{{{/raw}}}}', ''); } } //# sourceMappingURL=get-title.js.map