UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

28 lines 1.14 kB
import Handlebars from 'handlebars'; import { getShortSha } from '../github/commit-formatters.js'; /* * Returns the name of the backport branch without remote name * * Examples: * For a single PR: `backport/7.x/pr-1234` * For a single commit: `backport/7.x/commit-abcdef` * For multiple: `backport/7.x/pr-1234_commit-abcdef` */ export function getBackportBranchName({ options, targetBranch, commits, }) { const refValues = commits .map((commit) => commit.sourcePullRequest ? `pr-${commit.sourcePullRequest.number}` : `commit-${getShortSha(commit.sourceCommit.sha)}`) .join('_') .slice(0, 200); const sourcePullRequest = commits.at(0)?.sourcePullRequest; // assume that all commits are from the same PR const defaultBackportBranchName = 'backport/{{targetBranch}}/{{refValues}}'; const backportBranchName = options.backportBranchName ?? defaultBackportBranchName; const template = Handlebars.compile(backportBranchName); return template({ sourcePullRequest, targetBranch, refValues, }); } //# sourceMappingURL=get-backport-branch-name.js.map