refactor(migrations): branchPrefix (#14910)

This commit is contained in:
Maksim 2022-04-02 21:07:15 +02:00 committed by GitHub
parent a12f8377bc
commit bbb6eb122e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 8 deletions

View file

@ -118,14 +118,6 @@ export function migrateConfig(
regEx(/{{depNameShort}}/g),
'{{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)) {
delete migratedConfig.semanticPrefix;
let [text] = val.split(':') as any; // TODO: fixme

View 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
);
});
});

View 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));
}
}
}

View file

@ -10,6 +10,7 @@ import { AutomergeTypeMigration } from './custom/automerge-type-migration';
import { BaseBranchMigration } from './custom/base-branch-migration';
import { BinarySourceMigration } from './custom/binary-source-migration';
import { BranchNameMigration } from './custom/branch-name-migration';
import { BranchPrefixMigration } from './custom/branch-prefix-migration';
import { CompatibilityMigration } from './custom/compatibility-migration';
import { ComposerIgnorePlatformReqsMigration } from './custom/composer-ignore-platform-reqs-migration';
import { EnabledManagersMigration } from './custom/enabled-managers-migration';
@ -76,6 +77,7 @@ export class MigrationsService {
BaseBranchMigration,
BinarySourceMigration,
BranchNameMigration,
BranchPrefixMigration,
CompatibilityMigration,
ComposerIgnorePlatformReqsMigration,
EnabledManagersMigration,