mirror of
https://github.com/kiegroup/git-backporting.git
synced 2025-05-10 18:53:43 +00:00
fix(issue-57): truncate the bp branch name (#58)
fix: https://github.com/kiegroup/git-backporting/issues/57 This pr will ensure that if the provided/generated backport branch name exceede the maximum branch name length set for git, which is 250 chars, it truncates that name to 250 chars exactly. In order to include as much commits as possible the branch name will contain by default the shortened version of all commits
This commit is contained in:
parent
91782505ce
commit
ead1322c0f
8 changed files with 169 additions and 88 deletions
11
dist/cli/index.js
vendored
11
dist/cli/index.js
vendored
|
@ -1192,7 +1192,16 @@ class Runner {
|
|||
await git.clone(configs.originalPullRequest.targetRepo.cloneUrl, configs.folder, configs.targetBranch);
|
||||
// 5. create new branch from target one and checkout
|
||||
this.logger.debug("Creating local branch..");
|
||||
const backportBranch = backportPR.branchName ?? `bp-${configs.targetBranch}-${originalPR.commits.join("-")}`;
|
||||
let backportBranch = backportPR.branchName;
|
||||
if (backportBranch === undefined || backportBranch.trim() === "") {
|
||||
// for each commit takes the first 7 chars that are enough to uniquely identify them in most of the projects
|
||||
const concatenatedCommits = originalPR.commits.map(c => c.slice(0, 7)).join("-");
|
||||
backportBranch = `bp-${configs.targetBranch}-${concatenatedCommits}`;
|
||||
}
|
||||
if (backportBranch.length > 250) {
|
||||
this.logger.warn(`Backport branch (length=${backportBranch.length}) exceeded the max length of 250 chars, branch name truncated!`);
|
||||
backportBranch = backportBranch.slice(0, 250);
|
||||
}
|
||||
await git.createLocalBranch(configs.folder, backportBranch);
|
||||
// 6. fetch pull request remote if source owner != target owner or pull request still open
|
||||
if (configs.originalPullRequest.sourceRepo.owner !== configs.originalPullRequest.targetRepo.owner ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue