From 47feeb4f43e02be8489cb7ea9f2e01862ef36701 Mon Sep 17 00:00:00 2001 From: Maksim <m.v.sharipov@gmail.com> Date: Mon, 14 Mar 2022 06:09:53 +0100 Subject: [PATCH] refactor(migrations): automergePatch (#14637) --- lib/config/migration.ts | 4 -- .../custom/automerge-patch-migration.spec.ts | 47 +++++++++++++++++++ .../custom/automerge-patch-migration.ts | 15 ++++++ lib/config/migrations/migrations-service.ts | 2 + 4 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 lib/config/migrations/custom/automerge-patch-migration.spec.ts create mode 100644 lib/config/migrations/custom/automerge-patch-migration.ts diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 4a480968d2..796c1c83e8 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -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) && diff --git a/lib/config/migrations/custom/automerge-patch-migration.spec.ts b/lib/config/migrations/custom/automerge-patch-migration.spec.ts new file mode 100644 index 0000000000..bc7014fa54 --- /dev/null +++ b/lib/config/migrations/custom/automerge-patch-migration.spec.ts @@ -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, + }, + } + ); + }); +}); diff --git a/lib/config/migrations/custom/automerge-patch-migration.ts b/lib/config/migrations/custom/automerge-patch-migration.ts new file mode 100644 index 0000000000..67daf67f8e --- /dev/null +++ b/lib/config/migrations/custom/automerge-patch-migration.ts @@ -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); + } +} diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 7e8b526f2b..67a16527f4 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -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, -- GitLab