Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new branchNameStrict configuration flag #17216

Merged
merged 16 commits into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/usage/configuration-options.md
Expand Up @@ -2911,3 +2911,7 @@ To disable the vulnerability alerts feature, set `enabled=false` in a `vulnerabi
}
}
```

## strictBranchSlugify

By default, Renovate does not use strict-mode when slugifying the branch name. To enforce strict-mode and prevent any special characters within the branch name, set this to `true`
setchy marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions lib/config/options/index.ts
Expand Up @@ -2342,6 +2342,12 @@ const options: RenovateOptions[] = [
default: false,
supportedPlatforms: ['github'],
},
{
name: 'strictBranchSlugify',
description: `Whether to be strict about the use of special characters in the branch name.`,
type: 'boolean',
default: false,
},
];

export function getOptions(): RenovateOptions[] {
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Expand Up @@ -69,6 +69,7 @@ export interface RenovateSharedConfig {
semanticCommits?: 'auto' | 'enabled' | 'disabled';
semanticCommitScope?: string | null;
semanticCommitType?: string;
strictBranchSlugify?: boolean;
suppressNotifications?: string[];
timezone?: string;
unicodeEmoji?: boolean;
Expand Down
34 changes: 32 additions & 2 deletions lib/workers/repository/updates/branch-name.spec.ts
Expand Up @@ -230,14 +230,14 @@ describe('workers/repository/updates/branch-name', () => {
groupName: 'invalid branch name.lock',
group: { branchName: 'renovate/{{groupSlug}}' },
},
expectedBranchName: 'renovate/invalid-branch-namelock',
expectedBranchName: 'renovate/invalid-branch-name',
},
{
upgrade: {
groupName: '.a-bad- name:@.lock',
group: { branchName: 'renovate/{{groupSlug}}' },
},
expectedBranchName: 'renovate/a-bad-namelock',
expectedBranchName: 'renovate/a-bad-name-@',
},
{
upgrade: { branchName: 'renovate/bad-branch-name1..' },
Expand Down Expand Up @@ -293,5 +293,35 @@ describe('workers/repository/updates/branch-name', () => {
expect(fixture.upgrade.branchName).toEqual(fixture.expectedBranchName);
});
});

it('strict branch slugify enabled', () => {
const upgrade: RenovateConfig = {
strictBranchSlugify: true,
groupName: '[some] group name.#$%version',
group: {
branchName: '{{groupSlug}}-{{branchTopic}}',
branchTopic: 'grouptopic',
},
};
generateBranchName(upgrade);
expect(upgrade.branchName).toBe(
'some-group-namedollarpercentversion-grouptopic'
setchy marked this conversation as resolved.
Show resolved Hide resolved
);
});

it('strict branch slugify disabled', () => {
const upgrade: RenovateConfig = {
strictBranchSlugify: false,
groupName: '[some] group name.#$%version',
group: {
branchName: '{{groupSlug}}-{{branchTopic}}',
branchTopic: 'grouptopic',
},
};
generateBranchName(upgrade);
expect(upgrade.branchName).toBe(
'some-group-name.dollarpercentversion-grouptopic'
);
});
});
});
2 changes: 1 addition & 1 deletion lib/workers/repository/updates/branch-name.ts
Expand Up @@ -43,7 +43,7 @@ export function generateBranchName(update: RenovateConfig): void {
);
update.groupSlug = slugify(update.groupSlug ?? update.groupName, {
lower: true,
strict: true,
strict: update.strictBranchSlugify,
});
if (update.updateType === 'major' && update.separateMajorMinor) {
if (update.separateMultipleMajor) {
Expand Down