refactor(migrations): automergePatch (#14637)

This commit is contained in:
Maksim 2022-03-14 06:09:53 +01:00 committed by GitHub
parent e99b1daf57
commit 47feeb4f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 4 deletions

View file

@ -201,10 +201,6 @@ export function migrateConfig(
} else if (key === 'separateMajorReleases') {
delete migratedConfig.separateMultipleMajor;
migratedConfig.separateMajorMinor = val;
} else if (key === 'automergePatch') {
migratedConfig.patch = migratedConfig.patch || {};
migratedConfig.patch.automerge = !!val;
delete migratedConfig[key];
} else if (
key === 'automerge' &&
is.string(val) &&

View file

@ -0,0 +1,47 @@
import { AutomergePatchMigration } from './automerge-patch-migration';
describe('config/migrations/custom/automerge-patch-migration', () => {
it('should migrate value to object', () => {
expect(AutomergePatchMigration).toMigrate(
{
automergePatch: 'some-value',
},
{
patch: {
automerge: true,
},
}
);
});
it('should migrate value to object and concat with existing minor object', () => {
expect(AutomergePatchMigration).toMigrate(
{
automergePatch: 'some-value',
patch: {
matchFiles: ['test'],
},
},
{
patch: {
automerge: true,
matchFiles: ['test'],
},
}
);
});
it('should ignore non object minor value', () => {
expect(AutomergePatchMigration).toMigrate(
{
automergePatch: 'some-value',
patch: null,
},
{
patch: {
automerge: true,
},
}
);
});
});

View file

@ -0,0 +1,15 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';
export class AutomergePatchMigration extends AbstractMigration {
override readonly deprecated = true;
override readonly propertyName = 'automergePatch';
override run(value: unknown): void {
const patch = this.get('patch');
const newPatch = is.object(patch) ? patch : {};
newPatch.automerge = Boolean(value);
this.setHard('patch', newPatch);
}
}

View file

@ -4,6 +4,7 @@ import { RemovePropertyMigration } from './base/remove-property-migration';
import { RenamePropertyMigration } from './base/rename-property-migration';
import { AutomergeMajorMigration } from './custom/automerge-major-migration';
import { AutomergeMinorMigration } from './custom/automerge-minor-migration';
import { AutomergePatchMigration } from './custom/automerge-patch-migration';
import { AutomergeTypeMigration } from './custom/automerge-type-migration';
import { BinarySourceMigration } from './custom/binary-source-migration';
import { CompatibilityMigration } from './custom/compatibility-migration';
@ -59,6 +60,7 @@ export class MigrationsService {
static readonly customMigrations: ReadonlyArray<MigrationConstructor> = [
AutomergeMajorMigration,
AutomergeMinorMigration,
AutomergePatchMigration,
AutomergeTypeMigration,
BinarySourceMigration,
CompatibilityMigration,