backport
Version:
A CLI tool that automates the process of backporting commits
35 lines • 1.5 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBackportBranchName = void 0;
const handlebars_1 = __importDefault(require("handlebars"));
const commitFormatters_1 = require("../github/commitFormatters");
/*
* 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`
*/
function getBackportBranchName({ options, targetBranch, commits, }) {
const refValues = commits
.map((commit) => commit.sourcePullRequest
? `pr-${commit.sourcePullRequest.number}`
: `commit-${(0, commitFormatters_1.getShortSha)(commit.sourceCommit.sha)}`)
.join('_')
.slice(0, 200);
const sourcePullRequest = commits[0].sourcePullRequest; // assume that all commits are from the same PR
const defaultBackportBranchName = 'backport/{{targetBranch}}/{{refValues}}';
const backportBranchName = options.backportBranchName ?? defaultBackportBranchName;
const template = handlebars_1.default.compile(backportBranchName);
return template({
sourcePullRequest,
targetBranch,
refValues,
});
}
exports.getBackportBranchName = getBackportBranchName;
//# sourceMappingURL=getBackportBranchName.js.map