mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 23:16:26 +00:00
refactor(migrations): branchPrefix (#14910)
This commit is contained in:
parent
a12f8377bc
commit
bbb6eb122e
4 changed files with 55 additions and 8 deletions
|
@ -118,14 +118,6 @@ export function migrateConfig(
|
||||||
regEx(/{{depNameShort}}/g),
|
regEx(/{{depNameShort}}/g),
|
||||||
'{{depName}}'
|
'{{depName}}'
|
||||||
);
|
);
|
||||||
} else if (
|
|
||||||
key === 'branchPrefix' &&
|
|
||||||
is.string(val) &&
|
|
||||||
val.includes('{{')
|
|
||||||
) {
|
|
||||||
const templateIndex = val.indexOf(`{{`);
|
|
||||||
migratedConfig.branchPrefix = val.substring(0, templateIndex);
|
|
||||||
migratedConfig.additionalBranchPrefix = val.substring(templateIndex);
|
|
||||||
} else if (key === 'semanticPrefix' && is.string(val)) {
|
} else if (key === 'semanticPrefix' && is.string(val)) {
|
||||||
delete migratedConfig.semanticPrefix;
|
delete migratedConfig.semanticPrefix;
|
||||||
let [text] = val.split(':') as any; // TODO: fixme
|
let [text] = val.split(':') as any; // TODO: fixme
|
||||||
|
|
39
lib/config/migrations/custom/branch-prefix-migration.spec.ts
Normal file
39
lib/config/migrations/custom/branch-prefix-migration.spec.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import { BranchPrefixMigration } from './branch-prefix-migration';
|
||||||
|
|
||||||
|
describe('config/migrations/custom/branch-prefix-migration', () => {
|
||||||
|
it('should migrate template', () => {
|
||||||
|
expect(BranchPrefixMigration).toMigrate(
|
||||||
|
{
|
||||||
|
branchPrefix: 'renovate/{{parentDir}}-',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
additionalBranchPrefix: '{{parentDir}}-',
|
||||||
|
branchPrefix: 'renovate/',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore string without template', () => {
|
||||||
|
expect(BranchPrefixMigration).toMigrate(
|
||||||
|
{
|
||||||
|
branchPrefix: 'test',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
branchPrefix: 'test',
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore non string without template', () => {
|
||||||
|
expect(BranchPrefixMigration).toMigrate(
|
||||||
|
{
|
||||||
|
branchPrefix: true,
|
||||||
|
} as any,
|
||||||
|
{
|
||||||
|
branchPrefix: true,
|
||||||
|
} as any,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
14
lib/config/migrations/custom/branch-prefix-migration.ts
Normal file
14
lib/config/migrations/custom/branch-prefix-migration.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import is from '@sindresorhus/is';
|
||||||
|
import { AbstractMigration } from '../base/abstract-migration';
|
||||||
|
|
||||||
|
export class BranchPrefixMigration extends AbstractMigration {
|
||||||
|
override readonly propertyName = 'branchPrefix';
|
||||||
|
|
||||||
|
override run(value: unknown): void {
|
||||||
|
if (is.string(value) && value.includes('{{')) {
|
||||||
|
const templateIndex = value.indexOf(`{{`);
|
||||||
|
this.rewrite(value.substring(0, templateIndex));
|
||||||
|
this.setHard('additionalBranchPrefix', value.substring(templateIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import { AutomergeTypeMigration } from './custom/automerge-type-migration';
|
||||||
import { BaseBranchMigration } from './custom/base-branch-migration';
|
import { BaseBranchMigration } from './custom/base-branch-migration';
|
||||||
import { BinarySourceMigration } from './custom/binary-source-migration';
|
import { BinarySourceMigration } from './custom/binary-source-migration';
|
||||||
import { BranchNameMigration } from './custom/branch-name-migration';
|
import { BranchNameMigration } from './custom/branch-name-migration';
|
||||||
|
import { BranchPrefixMigration } from './custom/branch-prefix-migration';
|
||||||
import { CompatibilityMigration } from './custom/compatibility-migration';
|
import { CompatibilityMigration } from './custom/compatibility-migration';
|
||||||
import { ComposerIgnorePlatformReqsMigration } from './custom/composer-ignore-platform-reqs-migration';
|
import { ComposerIgnorePlatformReqsMigration } from './custom/composer-ignore-platform-reqs-migration';
|
||||||
import { EnabledManagersMigration } from './custom/enabled-managers-migration';
|
import { EnabledManagersMigration } from './custom/enabled-managers-migration';
|
||||||
|
@ -76,6 +77,7 @@ export class MigrationsService {
|
||||||
BaseBranchMigration,
|
BaseBranchMigration,
|
||||||
BinarySourceMigration,
|
BinarySourceMigration,
|
||||||
BranchNameMigration,
|
BranchNameMigration,
|
||||||
|
BranchPrefixMigration,
|
||||||
CompatibilityMigration,
|
CompatibilityMigration,
|
||||||
ComposerIgnorePlatformReqsMigration,
|
ComposerIgnorePlatformReqsMigration,
|
||||||
EnabledManagersMigration,
|
EnabledManagersMigration,
|
||||||
|
|
Loading…
Reference in a new issue