Skip to content
Snippets Groups Projects
Commit 8319b1df authored by Yanis Benson's avatar Yanis Benson Committed by Rhys Arkins
Browse files

fix: remove double hyphens from branch names (#11186)

Removes double or more hyphens from branch names and replaces with a single hyphen.

Closes #8260

BREAKING CHANGE: Branches with double hyphens will be changed to single hyphens, which can result in some existing PRs being autoclosed and replacements opened.
parent 960b64e6
Branches
Tags ghost-0.41.1
No related merge requests found
...@@ -225,11 +225,11 @@ describe(getName(), () => { ...@@ -225,11 +225,11 @@ describe(getName(), () => {
}, },
{ {
upgrade: { branchName: 'renovate/bad-branch-^-name3' }, upgrade: { branchName: 'renovate/bad-branch-^-name3' },
expectedBranchName: 'renovate/bad-branch---name3', expectedBranchName: 'renovate/bad-branch-name3',
}, },
{ {
upgrade: { branchName: 'renovate/bad-branch-name : 4' }, upgrade: { branchName: 'renovate/bad-branch-name : 4' },
expectedBranchName: 'renovate/bad-branch-name---4', expectedBranchName: 'renovate/bad-branch-name-4',
}, },
{ {
upgrade: { branchName: 'renovate/bad-branch-name5/' }, upgrade: { branchName: 'renovate/bad-branch-name5/' },
...@@ -251,6 +251,14 @@ describe(getName(), () => { ...@@ -251,6 +251,14 @@ describe(getName(), () => {
upgrade: { branchName: 'renovate/bad-branch-name9.' }, upgrade: { branchName: 'renovate/bad-branch-name9.' },
expectedBranchName: 'renovate/bad-branch-name9', expectedBranchName: 'renovate/bad-branch-name9',
}, },
{
upgrade: { branchName: 'renovate/bad-branch--name10' },
expectedBranchName: 'renovate/bad-branch-name10',
},
{
upgrade: { branchName: 'renovate/bad--branch---name11' },
expectedBranchName: 'renovate/bad-branch-name11',
},
]; ];
fixtures.forEach((fixture) => { fixtures.forEach((fixture) => {
generateBranchName(fixture.upgrade); generateBranchName(fixture.upgrade);
......
...@@ -7,6 +7,7 @@ import * as template from '../../../util/template'; ...@@ -7,6 +7,7 @@ import * as template from '../../../util/template';
const MIN_HASH_LENGTH = 6; const MIN_HASH_LENGTH = 6;
const RE_MULTIPLE_DASH = /--+/g;
/** /**
* Clean git branch name * Clean git branch name
* *
...@@ -14,12 +15,14 @@ const MIN_HASH_LENGTH = 6; ...@@ -14,12 +15,14 @@ const MIN_HASH_LENGTH = 6;
* - leading dot/leading dot after slash * - leading dot/leading dot after slash
* - trailing dot * - trailing dot
* - whitespace * - whitespace
* - chained dashes(breaks markdown comments) are replaced by single dash
*/ */
function cleanBranchName(branchName: string): string { function cleanBranchName(branchName: string): string {
return cleanGitRef(branchName) return cleanGitRef(branchName)
.replace(/^\.|\.$/, '') // leading or trailing dot .replace(/^\.|\.$/, '') // leading or trailing dot
.replace(/\/\./g, '/') // leading dot after slash .replace(/\/\./g, '/') // leading dot after slash
.replace(/\s/g, ''); // whitespace .replace(/\s/g, '') // whitespace
.replace(RE_MULTIPLE_DASH, '-'); // chained dashes
} }
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment