From c71927766719d03f0f1a67d4168e3fde62d08c35 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sat, 9 Oct 2021 15:06:12 +0200 Subject: [PATCH 01/16] refactor: migrate inline with the same sort --- lib/config/migration.ts | 15 ++------ .../base/deprecate-property-migration.ts | 17 +++++++++ .../base/replace-property-migration.ts | 36 +++++++++++++++++++ lib/config/migrations/index.ts | 19 +--------- lib/config/migrations/migration.ts | 17 ++------- lib/config/migrations/migrations-runner.ts | 25 +++++++++++++ .../required-status-checks-migration.spec.ts | 14 +++----- .../required-status-checks-migration.ts | 18 ++++++---- 8 files changed, 99 insertions(+), 62 deletions(-) create mode 100644 lib/config/migrations/base/deprecate-property-migration.ts create mode 100644 lib/config/migrations/base/replace-property-migration.ts create mode 100644 lib/config/migrations/migrations-runner.ts diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 1fb49fc3a3caa3..832bf3d978058d 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -4,7 +4,7 @@ import { dequal } from 'dequal'; import { logger } from '../logger'; import { clone } from '../util/clone'; import { getGlobalConfig } from './global'; -import { applyMigrations } from './migrations'; +import { MigrationsRunner } from './migrations'; import { getOptions } from './options'; import { removedPresets } from './presets/common'; import type { @@ -20,7 +20,6 @@ const options = getOptions(); let optionTypes: Record; const removedOptions = [ - 'maintainYarnLock', 'yarnCacheFolder', 'yarnMaintenanceBranchName', 'yarnMaintenanceCommitMessage', @@ -49,7 +48,8 @@ export function migrateConfig( optionTypes[option.name] = option.type; }); } - const migratedConfig = clone(config) as MigratedRenovateConfig; + const newConfig = MigrationsRunner.runAllMigrations(config); + const migratedConfig = clone(newConfig) as MigratedRenovateConfig; const depTypes = [ 'dependencies', 'devDependencies', @@ -58,7 +58,6 @@ export function migrateConfig( 'peerDependencies', ]; const { migratePresets } = getGlobalConfig(); - applyMigrations(config, migratedConfig); for (const [key, val] of Object.entries(config)) { if (removedOptions.includes(key)) { delete migratedConfig[key]; @@ -179,8 +178,6 @@ export function migrateConfig( migratedConfig[key] = val.replace(/{{baseDir}}/g, '{{packageFileDir}}'); } else if (is.string(val) && val.includes('{{depNameShort}}')) { migratedConfig[key] = val.replace(/{{depNameShort}}/g, '{{depName}}'); - } else if (key === 'gitFs') { - delete migratedConfig.gitFs; } else if (key === 'rebaseStalePrs') { delete migratedConfig.rebaseStalePrs; if (!migratedConfig.rebaseWhen) { @@ -199,9 +196,6 @@ export function migrateConfig( if (val === false) { migratedConfig.rebaseWhen = 'never'; } - } else if (key === 'exposeEnv') { - migratedConfig.exposeAllEnv = val; - delete migratedConfig.exposeEnv; } else if (key === 'trustLevel') { delete migratedConfig.trustLevel; if (val === 'high') { @@ -319,9 +313,6 @@ export function migrateConfig( } else if (key === 'separateMajorReleases') { delete migratedConfig.separateMultipleMajor; migratedConfig.separateMajorMinor = val; - } else if (key === 'separatePatchReleases') { - delete migratedConfig.separatePatchReleases; - migratedConfig.separateMinorPatch = val; } else if (key === 'automergePatch') { migratedConfig.patch = migratedConfig.patch || {}; migratedConfig.patch.automerge = val == true; // eslint-disable-line eqeqeq diff --git a/lib/config/migrations/base/deprecate-property-migration.ts b/lib/config/migrations/base/deprecate-property-migration.ts new file mode 100644 index 00000000000000..0c94f791d9d1d3 --- /dev/null +++ b/lib/config/migrations/base/deprecate-property-migration.ts @@ -0,0 +1,17 @@ +import type { RenovateConfig } from '../../types'; +import type { Migration } from '../migration'; + +export class DeprecatePropertyMigration implements Migration { + private readonly deprecatedPropertyName: string; + + constructor(deprecatedPropertyName: string) { + this.deprecatedPropertyName = deprecatedPropertyName; + } + + run(config: RenovateConfig): RenovateConfig { + // eslint-disable-next-line no-param-reassign + delete config[this.deprecatedPropertyName]; + + return config; + } +} diff --git a/lib/config/migrations/base/replace-property-migration.ts b/lib/config/migrations/base/replace-property-migration.ts new file mode 100644 index 00000000000000..1edc164f5eb6d3 --- /dev/null +++ b/lib/config/migrations/base/replace-property-migration.ts @@ -0,0 +1,36 @@ +import type { RenovateConfig } from '../../types'; +import type { Migration } from '../migration'; + +export class ReplacePropertyMigration implements Migration { + protected readonly deprecatedPropertyName: string; + + protected readonly newPropertyName: string; + + constructor(deprecatedPropertyName: string, newPropertyName: string) { + this.deprecatedPropertyName = deprecatedPropertyName; + this.newPropertyName = newPropertyName; + } + + run(config: RenovateConfig): RenovateConfig { + return this.replaceProperty(config, config[this.deprecatedPropertyName]); + } + + protected replaceProperty( + config: RenovateConfig, + newValue?: unknown + ): Record { + const migratedConfig: Record = {}; + + for (const [key, value] of Object.entries(config)) { + if (key === this.deprecatedPropertyName) { + if (newValue !== undefined) { + migratedConfig[this.newPropertyName] = newValue; + } + } else { + migratedConfig[key] = value; + } + } + + return migratedConfig; + } +} diff --git a/lib/config/migrations/index.ts b/lib/config/migrations/index.ts index 1f6c961c293031..ee4f07de8a869f 100644 --- a/lib/config/migrations/index.ts +++ b/lib/config/migrations/index.ts @@ -1,18 +1 @@ -import { RenovateConfig } from '../types'; -import type { Migration } from './migration'; -import { RequiredStatusChecksMigration } from './required-status-checks-migration'; - -export function applyMigrations( - originalConfig: RenovateConfig, - migratedConfig: RenovateConfig -): RenovateConfig { - const migrations: Migration[] = [ - new RequiredStatusChecksMigration(originalConfig, migratedConfig), - ]; - - for (const migration of migrations) { - migration.migrate(); - } - - return migratedConfig; -} +export * from './migrations-runner'; diff --git a/lib/config/migrations/migration.ts b/lib/config/migrations/migration.ts index 616b96caeaeb17..d9d6bf24d2aeba 100644 --- a/lib/config/migrations/migration.ts +++ b/lib/config/migrations/migration.ts @@ -1,18 +1,5 @@ import type { RenovateConfig } from '../types'; -export abstract class Migration { - protected readonly originalConfig: RenovateConfig; - - protected readonly migratedConfig: RenovateConfig; - - constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { - this.originalConfig = originalConfig; - this.migratedConfig = migratedConfig; - } - - abstract migrate(): void; - - protected delete(property: string): void { - delete this.migratedConfig[property]; - } +export interface Migration { + run(config: RenovateConfig): RenovateConfig; } diff --git a/lib/config/migrations/migrations-runner.ts b/lib/config/migrations/migrations-runner.ts new file mode 100644 index 00000000000000..af12e101024c1d --- /dev/null +++ b/lib/config/migrations/migrations-runner.ts @@ -0,0 +1,25 @@ +import type { RenovateConfig } from '../types'; +import { DeprecatePropertyMigration } from './base/deprecate-property-migration'; +import { ReplacePropertyMigration } from './base/replace-property-migration'; +import type { Migration } from './migration'; +import { RequiredStatusChecksMigration } from './required-status-checks-migration'; + +export class MigrationsRunner { + private static readonly migrations: ReadonlyArray = [ + new DeprecatePropertyMigration('maintainYarnLock'), + new DeprecatePropertyMigration('gitFs'), + new ReplacePropertyMigration('exposeEnv', 'exposeAllEnv'), + new ReplacePropertyMigration('separatePatchReleases', 'separateMinorPatch'), + new RequiredStatusChecksMigration(), + ]; + + static runAllMigrations(originalConfig: RenovateConfig): RenovateConfig { + let config = originalConfig; + + for (const migration of MigrationsRunner.migrations) { + config = migration.run(config); + } + + return config; + } +} diff --git a/lib/config/migrations/required-status-checks-migration.spec.ts b/lib/config/migrations/required-status-checks-migration.spec.ts index afe9019ee573f3..d38b778f037481 100644 --- a/lib/config/migrations/required-status-checks-migration.spec.ts +++ b/lib/config/migrations/required-status-checks-migration.spec.ts @@ -1,20 +1,14 @@ +import type { RenovateConfig } from '../types'; import { RequiredStatusChecksMigration } from './required-status-checks-migration'; describe('config/migrations/required-status-checks-migration', () => { it('should migrate requiredStatusChecks=null to ignoreTests=true', () => { - const originalConfig: any = { + const originalConfig: Partial = { requiredStatusChecks: null, }; - const migratedConfig: any = { - requiredStatusChecks: null, - }; - const migration = new RequiredStatusChecksMigration( - originalConfig, - migratedConfig - ); + const migration = new RequiredStatusChecksMigration(); + const migratedConfig = migration.run(originalConfig); - expect(migratedConfig.requiredStatusChecks).toBeNull(); - migration.migrate(); expect(migratedConfig.requiredStatusChecks).toBeUndefined(); expect(migratedConfig.ignoreTests).toBeTrue(); }); diff --git a/lib/config/migrations/required-status-checks-migration.ts b/lib/config/migrations/required-status-checks-migration.ts index 3f6d64e28fe7cf..7b3aadce511b5d 100644 --- a/lib/config/migrations/required-status-checks-migration.ts +++ b/lib/config/migrations/required-status-checks-migration.ts @@ -1,11 +1,15 @@ -import { Migration } from './migration'; +import type { RenovateConfig } from '../types'; +import { ReplacePropertyMigration } from './base/replace-property-migration'; -export class RequiredStatusChecksMigration extends Migration { - public migrate(): void { - this.delete('requiredStatusChecks'); +export class RequiredStatusChecksMigration extends ReplacePropertyMigration { + constructor() { + super('requiredStatusChecks', 'ignoreTests'); + } - if (this.originalConfig.requiredStatusChecks === null) { - this.migratedConfig.ignoreTests = true; - } + override run(config: RenovateConfig): RenovateConfig { + return this.replaceProperty( + config, + config.requiredStatusChecks === null ? true : undefined + ); } } From cd03397484e9a3042fc22c49fc3915200da14aa2 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sun, 10 Oct 2021 17:29:48 +0200 Subject: [PATCH 02/16] refactor: migrations runner => migrations service --- lib/config/migration.ts | 4 ++-- lib/config/migrations/index.ts | 2 +- .../{migrations-runner.ts => migrations-service.ts} | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) rename lib/config/migrations/{migrations-runner.ts => migrations-service.ts} (82%) diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 832bf3d978058d..1de232a5e5e415 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -4,7 +4,7 @@ import { dequal } from 'dequal'; import { logger } from '../logger'; import { clone } from '../util/clone'; import { getGlobalConfig } from './global'; -import { MigrationsRunner } from './migrations'; +import { MigrationsService } from './migrations'; import { getOptions } from './options'; import { removedPresets } from './presets/common'; import type { @@ -48,7 +48,7 @@ export function migrateConfig( optionTypes[option.name] = option.type; }); } - const newConfig = MigrationsRunner.runAllMigrations(config); + const newConfig = MigrationsService.run(config); const migratedConfig = clone(newConfig) as MigratedRenovateConfig; const depTypes = [ 'dependencies', diff --git a/lib/config/migrations/index.ts b/lib/config/migrations/index.ts index ee4f07de8a869f..2831c79f22e53b 100644 --- a/lib/config/migrations/index.ts +++ b/lib/config/migrations/index.ts @@ -1 +1 @@ -export * from './migrations-runner'; +export { MigrationsService } from './migrations-service'; diff --git a/lib/config/migrations/migrations-runner.ts b/lib/config/migrations/migrations-service.ts similarity index 82% rename from lib/config/migrations/migrations-runner.ts rename to lib/config/migrations/migrations-service.ts index af12e101024c1d..65ef339bfc1b14 100644 --- a/lib/config/migrations/migrations-runner.ts +++ b/lib/config/migrations/migrations-service.ts @@ -4,7 +4,7 @@ import { ReplacePropertyMigration } from './base/replace-property-migration'; import type { Migration } from './migration'; import { RequiredStatusChecksMigration } from './required-status-checks-migration'; -export class MigrationsRunner { +export class MigrationsService { private static readonly migrations: ReadonlyArray = [ new DeprecatePropertyMigration('maintainYarnLock'), new DeprecatePropertyMigration('gitFs'), @@ -13,10 +13,10 @@ export class MigrationsRunner { new RequiredStatusChecksMigration(), ]; - static runAllMigrations(originalConfig: RenovateConfig): RenovateConfig { + static run(originalConfig: RenovateConfig): RenovateConfig { let config = originalConfig; - for (const migration of MigrationsRunner.migrations) { + for (const migration of MigrationsService.migrations) { config = migration.run(config); } From 3d41d5fba5b4cf5d0eb6c561a9e68f5efa78b5cc Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sun, 10 Oct 2021 20:29:19 +0200 Subject: [PATCH 03/16] refactor: move Migration to types --- lib/config/migrations/base/deprecate-property-migration.ts | 2 +- lib/config/migrations/base/replace-property-migration.ts | 2 +- lib/config/migrations/migrations-service.ts | 2 +- lib/types/migrations/index.ts | 1 + lib/{config => types}/migrations/migration.ts | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 lib/types/migrations/index.ts rename lib/{config => types}/migrations/migration.ts (57%) diff --git a/lib/config/migrations/base/deprecate-property-migration.ts b/lib/config/migrations/base/deprecate-property-migration.ts index 0c94f791d9d1d3..db256ef37ab2d6 100644 --- a/lib/config/migrations/base/deprecate-property-migration.ts +++ b/lib/config/migrations/base/deprecate-property-migration.ts @@ -1,5 +1,5 @@ +import type { Migration } from '../../../types/migrations'; import type { RenovateConfig } from '../../types'; -import type { Migration } from '../migration'; export class DeprecatePropertyMigration implements Migration { private readonly deprecatedPropertyName: string; diff --git a/lib/config/migrations/base/replace-property-migration.ts b/lib/config/migrations/base/replace-property-migration.ts index 1edc164f5eb6d3..0d8fabfe47fe33 100644 --- a/lib/config/migrations/base/replace-property-migration.ts +++ b/lib/config/migrations/base/replace-property-migration.ts @@ -1,5 +1,5 @@ +import type { Migration } from '../../../types/migrations'; import type { RenovateConfig } from '../../types'; -import type { Migration } from '../migration'; export class ReplacePropertyMigration implements Migration { protected readonly deprecatedPropertyName: string; diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 65ef339bfc1b14..91884fd9cfe73d 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -1,7 +1,7 @@ +import type { Migration } from '../../types/migrations'; import type { RenovateConfig } from '../types'; import { DeprecatePropertyMigration } from './base/deprecate-property-migration'; import { ReplacePropertyMigration } from './base/replace-property-migration'; -import type { Migration } from './migration'; import { RequiredStatusChecksMigration } from './required-status-checks-migration'; export class MigrationsService { diff --git a/lib/types/migrations/index.ts b/lib/types/migrations/index.ts new file mode 100644 index 00000000000000..377ad709ed3e52 --- /dev/null +++ b/lib/types/migrations/index.ts @@ -0,0 +1 @@ +export type { Migration } from './migration'; diff --git a/lib/config/migrations/migration.ts b/lib/types/migrations/migration.ts similarity index 57% rename from lib/config/migrations/migration.ts rename to lib/types/migrations/migration.ts index d9d6bf24d2aeba..e64b5ca9a11ed7 100644 --- a/lib/config/migrations/migration.ts +++ b/lib/types/migrations/migration.ts @@ -1,4 +1,4 @@ -import type { RenovateConfig } from '../types'; +import type { RenovateConfig } from '../../config/types'; export interface Migration { run(config: RenovateConfig): RenovateConfig; From d583c60eb667e57e67f82174ff072bf249aeeb33 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Mon, 11 Oct 2021 23:14:18 +0200 Subject: [PATCH 04/16] refactor: improve migrations --- lib/config/migration.ts | 3 --- .../base/deprecate-property-migration.spec.ts | 14 ++++++++++++++ .../base/replace-property-migration.spec.ts | 15 +++++++++++++++ .../migrations/base/replace-property-migration.ts | 6 +++++- .../migrations/ignore-node-modules-migration.ts | 12 ++++++++++++ lib/config/migrations/migrations-service.ts | 2 ++ 6 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 lib/config/migrations/base/deprecate-property-migration.spec.ts create mode 100644 lib/config/migrations/base/replace-property-migration.spec.ts create mode 100644 lib/config/migrations/ignore-node-modules-migration.ts diff --git a/lib/config/migration.ts b/lib/config/migration.ts index d3f37fcba46848..59c4eb8956f87b 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -317,9 +317,6 @@ export function migrateConfig( migratedConfig.patch = migratedConfig.patch || {}; migratedConfig.patch.automerge = val == true; // eslint-disable-line eqeqeq delete migratedConfig[key]; - } else if (key === 'ignoreNodeModules') { - delete migratedConfig.ignoreNodeModules; - migratedConfig.ignorePaths = val ? ['node_modules/'] : []; } else if ( key === 'automerge' && is.string(val) && diff --git a/lib/config/migrations/base/deprecate-property-migration.spec.ts b/lib/config/migrations/base/deprecate-property-migration.spec.ts new file mode 100644 index 00000000000000..fa56ad8854cd1b --- /dev/null +++ b/lib/config/migrations/base/deprecate-property-migration.spec.ts @@ -0,0 +1,14 @@ +import type { RenovateConfig } from '../../types'; +import { DeprecatePropertyMigration } from './deprecate-property-migration'; + +describe('config/migrations/base/deprecate-property-migration', () => { + it('should remove property from configuration', () => { + const originalConfig: Partial = { + test: 'test', + }; + const migration = new DeprecatePropertyMigration('test'); + const migratedConfig = migration.run(originalConfig); + + expect(migratedConfig.test).toBeUndefined(); + }); +}); diff --git a/lib/config/migrations/base/replace-property-migration.spec.ts b/lib/config/migrations/base/replace-property-migration.spec.ts new file mode 100644 index 00000000000000..1033b733f5251a --- /dev/null +++ b/lib/config/migrations/base/replace-property-migration.spec.ts @@ -0,0 +1,15 @@ +import type { RenovateConfig } from '../../types'; +import { ReplacePropertyMigration } from './replace-property-migration'; + +describe('config/migrations/base/replace-property-migration', () => { + it('should rename property', () => { + const originalConfig: Partial = { + old: 'test', + }; + const migration = new ReplacePropertyMigration('old', 'new'); + const migratedConfig = migration.run(originalConfig); + + expect(migratedConfig.old).toBeUndefined(); + expect(migratedConfig.new).toBe('test'); + }); +}); diff --git a/lib/config/migrations/base/replace-property-migration.ts b/lib/config/migrations/base/replace-property-migration.ts index 0d8fabfe47fe33..92f4234f58b84a 100644 --- a/lib/config/migrations/base/replace-property-migration.ts +++ b/lib/config/migrations/base/replace-property-migration.ts @@ -12,7 +12,11 @@ export class ReplacePropertyMigration implements Migration { } run(config: RenovateConfig): RenovateConfig { - return this.replaceProperty(config, config[this.deprecatedPropertyName]); + return this.replaceProperty(config, this.getNewValue(config)); + } + + protected getNewValue(config: RenovateConfig): unknown { + return config[this.deprecatedPropertyName]; } protected replaceProperty( diff --git a/lib/config/migrations/ignore-node-modules-migration.ts b/lib/config/migrations/ignore-node-modules-migration.ts new file mode 100644 index 00000000000000..38c7450f47bce5 --- /dev/null +++ b/lib/config/migrations/ignore-node-modules-migration.ts @@ -0,0 +1,12 @@ +import type { RenovateConfig } from '../types'; +import { ReplacePropertyMigration } from './base/replace-property-migration'; + +export class IgnoreNodeModulesMigration extends ReplacePropertyMigration { + constructor() { + super('ignoreNodeModules', 'ignorePaths'); + } + + protected override getNewValue(config: RenovateConfig): string[] { + return config[this.deprecatedPropertyName] ? ['node_modules/'] : []; + } +} diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 91884fd9cfe73d..1b36f3ca303f83 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -2,6 +2,7 @@ import type { Migration } from '../../types/migrations'; import type { RenovateConfig } from '../types'; import { DeprecatePropertyMigration } from './base/deprecate-property-migration'; import { ReplacePropertyMigration } from './base/replace-property-migration'; +import { IgnoreNodeModulesMigration } from './ignore-node-modules-migration'; import { RequiredStatusChecksMigration } from './required-status-checks-migration'; export class MigrationsService { @@ -11,6 +12,7 @@ export class MigrationsService { new ReplacePropertyMigration('exposeEnv', 'exposeAllEnv'), new ReplacePropertyMigration('separatePatchReleases', 'separateMinorPatch'), new RequiredStatusChecksMigration(), + new IgnoreNodeModulesMigration(), ]; static run(originalConfig: RenovateConfig): RenovateConfig { From 00f4472ca1d06211b37f2d586ec8381b762e5a3b Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Mon, 11 Oct 2021 23:38:56 +0200 Subject: [PATCH 05/16] refactor: migrations unit tests --- lib/config/migration.ts | 23 +--------- .../migrations/migrations-service.spec.ts | 30 +++++++++++++ lib/config/migrations/migrations-service.ts | 45 ++++++++++++++++--- 3 files changed, 70 insertions(+), 28 deletions(-) create mode 100644 lib/config/migrations/migrations-service.spec.ts diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 59c4eb8956f87b..f71d0d9a75ee7a 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -19,22 +19,6 @@ const options = getOptions(); let optionTypes: Record; -const removedOptions = [ - 'yarnCacheFolder', - 'yarnMaintenanceBranchName', - 'yarnMaintenanceCommitMessage', - 'yarnMaintenancePrTitle', - 'yarnMaintenancePrBody', - 'groupBranchName', - 'groupBranchName', - 'groupCommitMessage', - 'groupPrTitle', - 'groupPrBody', - 'statusCheckVerify', - 'lazyGrouping', - 'supportPolicy', -]; - // Returns a migrated config export function migrateConfig( config: RenovateConfig, @@ -59,9 +43,7 @@ export function migrateConfig( ]; const { migratePresets } = getGlobalConfig(); for (const [key, val] of Object.entries(config)) { - if (removedOptions.includes(key)) { - delete migratedConfig[key]; - } else if (key === 'pathRules') { + if (key === 'pathRules') { if (is.array(val)) { migratedConfig.packageRules = is.array(migratedConfig.packageRules) ? migratedConfig.packageRules @@ -304,9 +286,6 @@ export function migrateConfig( migratedConfig.major = migratedConfig.major || {}; migratedConfig.major.automerge = val == true; // eslint-disable-line eqeqeq delete migratedConfig[key]; - } else if (key === 'multipleMajorPrs') { - delete migratedConfig.multipleMajorPrs; - migratedConfig.separateMultipleMajor = val; } else if (key === 'renovateFork' && is.boolean(val)) { delete migratedConfig.renovateFork; migratedConfig.includeForks = val; diff --git a/lib/config/migrations/migrations-service.spec.ts b/lib/config/migrations/migrations-service.spec.ts new file mode 100644 index 00000000000000..daf7c358dccfe3 --- /dev/null +++ b/lib/config/migrations/migrations-service.spec.ts @@ -0,0 +1,30 @@ +import type { RenovateConfig } from '../types'; +import { MigrationsService } from './migrations-service'; + +describe('config/migrations/migrations-service', () => { + it('should remove deprecated properties', () => { + for (const property of MigrationsService.deprecatedProperties) { + const originalConfig: Partial = { + [property]: 'test', + }; + + const migratedConfig = MigrationsService.run(originalConfig); + expect(migratedConfig[property]).toBeUndefined(); + } + }); + + it('should rename renamed properties', () => { + for (const [ + oldPropertyName, + newPropertyName, + ] of MigrationsService.renamedProperties.entries()) { + const originalConfig: Partial = { + [oldPropertyName]: 'test', + }; + + const migratedConfig = MigrationsService.run(originalConfig); + expect(migratedConfig[oldPropertyName]).toBeUndefined(); + expect(migratedConfig[newPropertyName]).toBe('test'); + } + }); +}); diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 1b36f3ca303f83..7f2121dea4c440 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -6,19 +6,52 @@ import { IgnoreNodeModulesMigration } from './ignore-node-modules-migration'; import { RequiredStatusChecksMigration } from './required-status-checks-migration'; export class MigrationsService { - private static readonly migrations: ReadonlyArray = [ - new DeprecatePropertyMigration('maintainYarnLock'), - new DeprecatePropertyMigration('gitFs'), - new ReplacePropertyMigration('exposeEnv', 'exposeAllEnv'), - new ReplacePropertyMigration('separatePatchReleases', 'separateMinorPatch'), + static readonly deprecatedProperties: ReadonlySet = new Set([ + 'gitFs', + 'groupBranchName', + 'groupCommitMessage', + 'groupPrBody', + 'groupPrTitle', + 'lazyGrouping', + 'maintainYarnLock', + 'statusCheckVerify', + 'supportPolicy', + 'yarnCacheFolder', + 'yarnMaintenanceBranchName', + 'yarnMaintenanceCommitMessage', + 'yarnMaintenancePrBody', + 'yarnMaintenancePrTitle', + ]); + + static readonly renamedProperties: ReadonlyMap = new Map([ + ['exposeEnv', 'exposeAllEnv'], + ['separatePatchReleases', 'separateMinorPatch'], + ['multipleMajorPrs', 'separateMultipleMajor'], + ]); + + private static readonly customMigrations: ReadonlyArray = [ new RequiredStatusChecksMigration(), new IgnoreNodeModulesMigration(), ]; static run(originalConfig: RenovateConfig): RenovateConfig { + const migrations: Migration[] = [...MigrationsService.customMigrations]; let config = originalConfig; - for (const migration of MigrationsService.migrations) { + for (const property of MigrationsService.deprecatedProperties) { + migrations.push(new DeprecatePropertyMigration(property)); + } + + for (const [ + oldPropertyName, + newPropertyName, + ] of MigrationsService.renamedProperties.entries()) { + migrations.push( + new ReplacePropertyMigration(oldPropertyName, newPropertyName) + ); + } + + for (const migration of migrations) { config = migration.run(config); } From 4ad77bde20e3d5b6da714fe89d6d34a4e6f36a59 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Mon, 11 Oct 2021 23:45:38 +0200 Subject: [PATCH 06/16] refactor: improve migrations --- lib/config/migration.ts | 2 -- .../migrations/custom/binary-source-migration.ts | 14 ++++++++++++++ .../{ => custom}/ignore-node-modules-migration.ts | 4 ++-- .../required-status-checks-migration.spec.ts | 4 ++-- .../required-status-checks-migration.ts | 4 ++-- lib/config/migrations/migrations-service.ts | 10 ++++++---- 6 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 lib/config/migrations/custom/binary-source-migration.ts rename lib/config/migrations/{ => custom}/ignore-node-modules-migration.ts (69%) rename lib/config/migrations/{ => custom}/required-status-checks-migration.spec.ts (79%) rename lib/config/migrations/{ => custom}/required-status-checks-migration.ts (71%) diff --git a/lib/config/migration.ts b/lib/config/migration.ts index f71d0d9a75ee7a..f64dac74e0d83c 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -487,8 +487,6 @@ export function migrateConfig( migratedConfig.suppressNotifications || []; migratedConfig.suppressNotifications.push('deprecationWarningIssues'); } - } else if (key === 'binarySource' && val === 'auto') { - migratedConfig.binarySource = 'global'; } else if (key === 'composerIgnorePlatformReqs') { if (val === true) { migratedConfig.composerIgnorePlatformReqs = []; diff --git a/lib/config/migrations/custom/binary-source-migration.ts b/lib/config/migrations/custom/binary-source-migration.ts new file mode 100644 index 00000000000000..7854bab6f669ba --- /dev/null +++ b/lib/config/migrations/custom/binary-source-migration.ts @@ -0,0 +1,14 @@ +import type { RenovateConfig } from '../../types'; +import { ReplacePropertyMigration } from '../base/replace-property-migration'; + +export class BinarySourceMigration extends ReplacePropertyMigration { + constructor() { + super('binarySource', 'binarySource'); + } + + protected override getNewValue(config: RenovateConfig): string | unknown { + return config[this.deprecatedPropertyName] === 'auto' + ? 'global' + : config[this.deprecatedPropertyName]; + } +} diff --git a/lib/config/migrations/ignore-node-modules-migration.ts b/lib/config/migrations/custom/ignore-node-modules-migration.ts similarity index 69% rename from lib/config/migrations/ignore-node-modules-migration.ts rename to lib/config/migrations/custom/ignore-node-modules-migration.ts index 38c7450f47bce5..d4a0445d91b392 100644 --- a/lib/config/migrations/ignore-node-modules-migration.ts +++ b/lib/config/migrations/custom/ignore-node-modules-migration.ts @@ -1,5 +1,5 @@ -import type { RenovateConfig } from '../types'; -import { ReplacePropertyMigration } from './base/replace-property-migration'; +import type { RenovateConfig } from '../../types'; +import { ReplacePropertyMigration } from '../base/replace-property-migration'; export class IgnoreNodeModulesMigration extends ReplacePropertyMigration { constructor() { diff --git a/lib/config/migrations/required-status-checks-migration.spec.ts b/lib/config/migrations/custom/required-status-checks-migration.spec.ts similarity index 79% rename from lib/config/migrations/required-status-checks-migration.spec.ts rename to lib/config/migrations/custom/required-status-checks-migration.spec.ts index d38b778f037481..340333cc6f9936 100644 --- a/lib/config/migrations/required-status-checks-migration.spec.ts +++ b/lib/config/migrations/custom/required-status-checks-migration.spec.ts @@ -1,7 +1,7 @@ -import type { RenovateConfig } from '../types'; +import type { RenovateConfig } from '../../types'; import { RequiredStatusChecksMigration } from './required-status-checks-migration'; -describe('config/migrations/required-status-checks-migration', () => { +describe('config/migrations/custom/required-status-checks-migration', () => { it('should migrate requiredStatusChecks=null to ignoreTests=true', () => { const originalConfig: Partial = { requiredStatusChecks: null, diff --git a/lib/config/migrations/required-status-checks-migration.ts b/lib/config/migrations/custom/required-status-checks-migration.ts similarity index 71% rename from lib/config/migrations/required-status-checks-migration.ts rename to lib/config/migrations/custom/required-status-checks-migration.ts index 7b3aadce511b5d..76a16d0ac0f232 100644 --- a/lib/config/migrations/required-status-checks-migration.ts +++ b/lib/config/migrations/custom/required-status-checks-migration.ts @@ -1,5 +1,5 @@ -import type { RenovateConfig } from '../types'; -import { ReplacePropertyMigration } from './base/replace-property-migration'; +import type { RenovateConfig } from '../../types'; +import { ReplacePropertyMigration } from '../base/replace-property-migration'; export class RequiredStatusChecksMigration extends ReplacePropertyMigration { constructor() { diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 7f2121dea4c440..b4dfc1b8e0ef5c 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -2,8 +2,9 @@ import type { Migration } from '../../types/migrations'; import type { RenovateConfig } from '../types'; import { DeprecatePropertyMigration } from './base/deprecate-property-migration'; import { ReplacePropertyMigration } from './base/replace-property-migration'; -import { IgnoreNodeModulesMigration } from './ignore-node-modules-migration'; -import { RequiredStatusChecksMigration } from './required-status-checks-migration'; +import { BinarySourceMigration } from './custom/binary-source-migration'; +import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration'; +import { RequiredStatusChecksMigration } from './custom/required-status-checks-migration'; export class MigrationsService { static readonly deprecatedProperties: ReadonlySet = new Set([ @@ -30,12 +31,13 @@ export class MigrationsService { ]); private static readonly customMigrations: ReadonlyArray = [ - new RequiredStatusChecksMigration(), + new BinarySourceMigration(), new IgnoreNodeModulesMigration(), + new RequiredStatusChecksMigration(), ]; static run(originalConfig: RenovateConfig): RenovateConfig { - const migrations: Migration[] = [...MigrationsService.customMigrations]; + const migrations = [...MigrationsService.customMigrations]; let config = originalConfig; for (const property of MigrationsService.deprecatedProperties) { From 63701dc665415c4389b3fdaa411b93487ee1d397 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Wed, 13 Oct 2021 13:35:24 +0200 Subject: [PATCH 07/16] refactor: migrations --- lib/config/migration.ts | 7 -- .../migrations/base/abstract-migration.ts | 26 ++++++++ .../base/deprecate-property-migration.spec.ts | 14 ---- .../base/deprecate-property-migration.ts | 17 ----- .../base/remove-property-migration.spec.ts | 21 ++++++ .../base/remove-property-migration.ts | 7 ++ .../base/rename-property-migration.spec.ts | 23 +++++++ .../base/rename-property-migration.ts | 23 +++++++ .../base/replace-property-migration.spec.ts | 15 ----- .../base/replace-property-migration.ts | 40 ------------ .../custom/binary-source-migration.ts | 16 ++--- .../custom/ignore-node-modules-migration.ts | 16 +++-- .../required-status-checks-migration.spec.ts | 10 ++- .../required-status-checks-migration.ts | 19 +++--- .../custom/trust-level-migration.ts | 18 +++++ .../migrations/migrations-service.spec.ts | 2 +- lib/config/migrations/migrations-service.ts | 65 ++++++++++++++----- lib/types/migrations/migration.ts | 5 +- 18 files changed, 204 insertions(+), 140 deletions(-) create mode 100644 lib/config/migrations/base/abstract-migration.ts delete mode 100644 lib/config/migrations/base/deprecate-property-migration.spec.ts delete mode 100644 lib/config/migrations/base/deprecate-property-migration.ts create mode 100644 lib/config/migrations/base/remove-property-migration.spec.ts create mode 100644 lib/config/migrations/base/remove-property-migration.ts create mode 100644 lib/config/migrations/base/rename-property-migration.spec.ts create mode 100644 lib/config/migrations/base/rename-property-migration.ts delete mode 100644 lib/config/migrations/base/replace-property-migration.spec.ts delete mode 100644 lib/config/migrations/base/replace-property-migration.ts create mode 100644 lib/config/migrations/custom/trust-level-migration.ts diff --git a/lib/config/migration.ts b/lib/config/migration.ts index f64dac74e0d83c..058be97a6a946f 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -178,13 +178,6 @@ export function migrateConfig( if (val === false) { migratedConfig.rebaseWhen = 'never'; } - } else if (key === 'trustLevel') { - delete migratedConfig.trustLevel; - if (val === 'high') { - migratedConfig.allowCustomCrateRegistries ??= true; - migratedConfig.allowScripts ??= true; - migratedConfig.exposeAllEnv ??= true; - } } else if (key === 'ignoreNpmrcFile') { delete migratedConfig.ignoreNpmrcFile; if (!is.string(migratedConfig.npmrc)) { diff --git a/lib/config/migrations/base/abstract-migration.ts b/lib/config/migrations/base/abstract-migration.ts new file mode 100644 index 00000000000000..23ffb5563a70ca --- /dev/null +++ b/lib/config/migrations/base/abstract-migration.ts @@ -0,0 +1,26 @@ +import type { Migration } from '../../../types/migrations'; +import type { RenovateConfig } from '../../types'; + +export abstract class AbstractMigration implements Migration { + readonly propertyName: string; + + protected readonly originalConfig: RenovateConfig; + + protected readonly migratedConfig: RenovateConfig; + + constructor( + propertyName: string, + originalConfig: RenovateConfig, + migratedConfig: RenovateConfig + ) { + this.propertyName = propertyName; + this.originalConfig = originalConfig; + this.migratedConfig = migratedConfig; + } + + abstract run(): void; + + protected delete(property: string): void { + delete this.migratedConfig[property]; + } +} diff --git a/lib/config/migrations/base/deprecate-property-migration.spec.ts b/lib/config/migrations/base/deprecate-property-migration.spec.ts deleted file mode 100644 index fa56ad8854cd1b..00000000000000 --- a/lib/config/migrations/base/deprecate-property-migration.spec.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { RenovateConfig } from '../../types'; -import { DeprecatePropertyMigration } from './deprecate-property-migration'; - -describe('config/migrations/base/deprecate-property-migration', () => { - it('should remove property from configuration', () => { - const originalConfig: Partial = { - test: 'test', - }; - const migration = new DeprecatePropertyMigration('test'); - const migratedConfig = migration.run(originalConfig); - - expect(migratedConfig.test).toBeUndefined(); - }); -}); diff --git a/lib/config/migrations/base/deprecate-property-migration.ts b/lib/config/migrations/base/deprecate-property-migration.ts deleted file mode 100644 index db256ef37ab2d6..00000000000000 --- a/lib/config/migrations/base/deprecate-property-migration.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Migration } from '../../../types/migrations'; -import type { RenovateConfig } from '../../types'; - -export class DeprecatePropertyMigration implements Migration { - private readonly deprecatedPropertyName: string; - - constructor(deprecatedPropertyName: string) { - this.deprecatedPropertyName = deprecatedPropertyName; - } - - run(config: RenovateConfig): RenovateConfig { - // eslint-disable-next-line no-param-reassign - delete config[this.deprecatedPropertyName]; - - return config; - } -} diff --git a/lib/config/migrations/base/remove-property-migration.spec.ts b/lib/config/migrations/base/remove-property-migration.spec.ts new file mode 100644 index 00000000000000..f319f0eb4ddafc --- /dev/null +++ b/lib/config/migrations/base/remove-property-migration.spec.ts @@ -0,0 +1,21 @@ +import type { RenovateConfig } from '../../types'; +import { RemovePropertyMigration } from './remove-property-migration'; + +describe('config/migrations/base/remove-property-migration', () => { + it('should remove property from configuration', () => { + const originalConfig: RenovateConfig = { + test: 'test', + }; + const migratedConfig: RenovateConfig = { + test: 'test', + }; + const migration = new RemovePropertyMigration( + 'test', + originalConfig, + migratedConfig + ); + migration.run(); + + expect(migratedConfig.test).toBeUndefined(); + }); +}); diff --git a/lib/config/migrations/base/remove-property-migration.ts b/lib/config/migrations/base/remove-property-migration.ts new file mode 100644 index 00000000000000..0b2ad2496963b2 --- /dev/null +++ b/lib/config/migrations/base/remove-property-migration.ts @@ -0,0 +1,7 @@ +import { AbstractMigration } from './abstract-migration'; + +export class RemovePropertyMigration extends AbstractMigration { + override run(): void { + this.delete(this.propertyName); + } +} diff --git a/lib/config/migrations/base/rename-property-migration.spec.ts b/lib/config/migrations/base/rename-property-migration.spec.ts new file mode 100644 index 00000000000000..06fea2aa6e7218 --- /dev/null +++ b/lib/config/migrations/base/rename-property-migration.spec.ts @@ -0,0 +1,23 @@ +import type { RenovateConfig } from '../../types'; +import { RenamePropertyMigration } from './rename-property-migration'; + +describe('config/migrations/base/rename-property-migration', () => { + it('should rename property', () => { + const originalConfig: RenovateConfig = { + old: 'test', + }; + const migratedConfig: RenovateConfig = { + old: 'test', + }; + const migration = new RenamePropertyMigration( + 'old', + 'new', + originalConfig, + migratedConfig + ); + migration.run(); + + expect(migratedConfig.old).toBeUndefined(); + expect(migratedConfig.new).toBe('test'); + }); +}); diff --git a/lib/config/migrations/base/rename-property-migration.ts b/lib/config/migrations/base/rename-property-migration.ts new file mode 100644 index 00000000000000..c317634be40ea4 --- /dev/null +++ b/lib/config/migrations/base/rename-property-migration.ts @@ -0,0 +1,23 @@ +import type { RenovateConfig } from '../../types'; +import { AbstractMigration } from './abstract-migration'; + +export class RenamePropertyMigration extends AbstractMigration { + protected readonly newPropertyName: string; + + constructor( + deprecatedPropertyName: string, + newPropertyName: string, + originalConfig: RenovateConfig, + migratedConfig: RenovateConfig + ) { + super(deprecatedPropertyName, originalConfig, migratedConfig); + this.newPropertyName = newPropertyName; + } + + override run(): void { + this.delete(this.propertyName); + + this.migratedConfig[this.newPropertyName] = + this.originalConfig[this.propertyName]; + } +} diff --git a/lib/config/migrations/base/replace-property-migration.spec.ts b/lib/config/migrations/base/replace-property-migration.spec.ts deleted file mode 100644 index 1033b733f5251a..00000000000000 --- a/lib/config/migrations/base/replace-property-migration.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { RenovateConfig } from '../../types'; -import { ReplacePropertyMigration } from './replace-property-migration'; - -describe('config/migrations/base/replace-property-migration', () => { - it('should rename property', () => { - const originalConfig: Partial = { - old: 'test', - }; - const migration = new ReplacePropertyMigration('old', 'new'); - const migratedConfig = migration.run(originalConfig); - - expect(migratedConfig.old).toBeUndefined(); - expect(migratedConfig.new).toBe('test'); - }); -}); diff --git a/lib/config/migrations/base/replace-property-migration.ts b/lib/config/migrations/base/replace-property-migration.ts deleted file mode 100644 index 92f4234f58b84a..00000000000000 --- a/lib/config/migrations/base/replace-property-migration.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { Migration } from '../../../types/migrations'; -import type { RenovateConfig } from '../../types'; - -export class ReplacePropertyMigration implements Migration { - protected readonly deprecatedPropertyName: string; - - protected readonly newPropertyName: string; - - constructor(deprecatedPropertyName: string, newPropertyName: string) { - this.deprecatedPropertyName = deprecatedPropertyName; - this.newPropertyName = newPropertyName; - } - - run(config: RenovateConfig): RenovateConfig { - return this.replaceProperty(config, this.getNewValue(config)); - } - - protected getNewValue(config: RenovateConfig): unknown { - return config[this.deprecatedPropertyName]; - } - - protected replaceProperty( - config: RenovateConfig, - newValue?: unknown - ): Record { - const migratedConfig: Record = {}; - - for (const [key, value] of Object.entries(config)) { - if (key === this.deprecatedPropertyName) { - if (newValue !== undefined) { - migratedConfig[this.newPropertyName] = newValue; - } - } else { - migratedConfig[key] = value; - } - } - - return migratedConfig; - } -} diff --git a/lib/config/migrations/custom/binary-source-migration.ts b/lib/config/migrations/custom/binary-source-migration.ts index 7854bab6f669ba..1452897133193b 100644 --- a/lib/config/migrations/custom/binary-source-migration.ts +++ b/lib/config/migrations/custom/binary-source-migration.ts @@ -1,14 +1,14 @@ import type { RenovateConfig } from '../../types'; -import { ReplacePropertyMigration } from '../base/replace-property-migration'; +import { AbstractMigration } from '../base/abstract-migration'; -export class BinarySourceMigration extends ReplacePropertyMigration { - constructor() { - super('binarySource', 'binarySource'); +export class BinarySourceMigration extends AbstractMigration { + constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { + super('binarySource', originalConfig, migratedConfig); } - protected override getNewValue(config: RenovateConfig): string | unknown { - return config[this.deprecatedPropertyName] === 'auto' - ? 'global' - : config[this.deprecatedPropertyName]; + override run(): void { + if (this.originalConfig.binarySource === 'auto') { + this.migratedConfig.binarySource = 'global'; + } } } diff --git a/lib/config/migrations/custom/ignore-node-modules-migration.ts b/lib/config/migrations/custom/ignore-node-modules-migration.ts index d4a0445d91b392..976b53df3cd0e0 100644 --- a/lib/config/migrations/custom/ignore-node-modules-migration.ts +++ b/lib/config/migrations/custom/ignore-node-modules-migration.ts @@ -1,12 +1,16 @@ import type { RenovateConfig } from '../../types'; -import { ReplacePropertyMigration } from '../base/replace-property-migration'; +import { AbstractMigration } from '../base/abstract-migration'; -export class IgnoreNodeModulesMigration extends ReplacePropertyMigration { - constructor() { - super('ignoreNodeModules', 'ignorePaths'); +export class IgnoreNodeModulesMigration extends AbstractMigration { + constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { + super('ignoreNodeModules', originalConfig, migratedConfig); } - protected override getNewValue(config: RenovateConfig): string[] { - return config[this.deprecatedPropertyName] ? ['node_modules/'] : []; + override run(): void { + this.delete(this.propertyName); + + this.migratedConfig.ignorePaths = this.originalConfig.ignoreNodeModules + ? ['node_modules/'] + : []; } } diff --git a/lib/config/migrations/custom/required-status-checks-migration.spec.ts b/lib/config/migrations/custom/required-status-checks-migration.spec.ts index 340333cc6f9936..1db005dd0da8e2 100644 --- a/lib/config/migrations/custom/required-status-checks-migration.spec.ts +++ b/lib/config/migrations/custom/required-status-checks-migration.spec.ts @@ -6,8 +6,14 @@ describe('config/migrations/custom/required-status-checks-migration', () => { const originalConfig: Partial = { requiredStatusChecks: null, }; - const migration = new RequiredStatusChecksMigration(); - const migratedConfig = migration.run(originalConfig); + const migratedConfig: Partial = { + requiredStatusChecks: null, + }; + const migration = new RequiredStatusChecksMigration( + originalConfig, + migratedConfig + ); + migration.run(); expect(migratedConfig.requiredStatusChecks).toBeUndefined(); expect(migratedConfig.ignoreTests).toBeTrue(); diff --git a/lib/config/migrations/custom/required-status-checks-migration.ts b/lib/config/migrations/custom/required-status-checks-migration.ts index 76a16d0ac0f232..cd06869c20e18c 100644 --- a/lib/config/migrations/custom/required-status-checks-migration.ts +++ b/lib/config/migrations/custom/required-status-checks-migration.ts @@ -1,15 +1,16 @@ import type { RenovateConfig } from '../../types'; -import { ReplacePropertyMigration } from '../base/replace-property-migration'; +import { AbstractMigration } from '../base/abstract-migration'; -export class RequiredStatusChecksMigration extends ReplacePropertyMigration { - constructor() { - super('requiredStatusChecks', 'ignoreTests'); +export class RequiredStatusChecksMigration extends AbstractMigration { + constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { + super('requiredStatusChecks', originalConfig, migratedConfig); } - override run(config: RenovateConfig): RenovateConfig { - return this.replaceProperty( - config, - config.requiredStatusChecks === null ? true : undefined - ); + override run(): void { + this.delete(this.propertyName); + + if (this.originalConfig.requiredStatusChecks === null) { + this.migratedConfig.ignoreTests = true; + } } } diff --git a/lib/config/migrations/custom/trust-level-migration.ts b/lib/config/migrations/custom/trust-level-migration.ts new file mode 100644 index 00000000000000..846cb8b8ee3cb0 --- /dev/null +++ b/lib/config/migrations/custom/trust-level-migration.ts @@ -0,0 +1,18 @@ +import type { RenovateConfig } from '../../types'; +import { AbstractMigration } from '../base/abstract-migration'; + +export class TrustLevelMigration extends AbstractMigration { + constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { + super('trustLevel', originalConfig, migratedConfig); + } + + override run(): void { + this.delete(this.propertyName); + + if (this.originalConfig.trustLevel === 'high') { + this.migratedConfig.allowCustomCrateRegistries ??= true; + this.migratedConfig.allowScripts ??= true; + this.migratedConfig.exposeAllEnv ??= true; + } + } +} diff --git a/lib/config/migrations/migrations-service.spec.ts b/lib/config/migrations/migrations-service.spec.ts index daf7c358dccfe3..9c9b658c9e9cae 100644 --- a/lib/config/migrations/migrations-service.spec.ts +++ b/lib/config/migrations/migrations-service.spec.ts @@ -3,7 +3,7 @@ import { MigrationsService } from './migrations-service'; describe('config/migrations/migrations-service', () => { it('should remove deprecated properties', () => { - for (const property of MigrationsService.deprecatedProperties) { + for (const property of MigrationsService.removedProperties) { const originalConfig: Partial = { [property]: 'test', }; diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index b4dfc1b8e0ef5c..599fcc451a501e 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -1,13 +1,14 @@ import type { Migration } from '../../types/migrations'; import type { RenovateConfig } from '../types'; -import { DeprecatePropertyMigration } from './base/deprecate-property-migration'; -import { ReplacePropertyMigration } from './base/replace-property-migration'; +import { RemovePropertyMigration } from './base/remove-property-migration'; +import { RenamePropertyMigration } from './base/rename-property-migration'; import { BinarySourceMigration } from './custom/binary-source-migration'; import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration'; import { RequiredStatusChecksMigration } from './custom/required-status-checks-migration'; +import { TrustLevelMigration } from './custom/trust-level-migration'; export class MigrationsService { - static readonly deprecatedProperties: ReadonlySet = new Set([ + static readonly removedProperties: ReadonlySet = new Set([ 'gitFs', 'groupBranchName', 'groupCommitMessage', @@ -30,18 +31,36 @@ export class MigrationsService { ['multipleMajorPrs', 'separateMultipleMajor'], ]); - private static readonly customMigrations: ReadonlyArray = [ - new BinarySourceMigration(), - new IgnoreNodeModulesMigration(), - new RequiredStatusChecksMigration(), - ]; - static run(originalConfig: RenovateConfig): RenovateConfig { - const migrations = [...MigrationsService.customMigrations]; - let config = originalConfig; + const migratedConfig: RenovateConfig = {}; + const migrations = MigrationsService.getMigrations( + originalConfig, + migratedConfig + ); - for (const property of MigrationsService.deprecatedProperties) { - migrations.push(new DeprecatePropertyMigration(property)); + for (const [key, value] of Object.entries(originalConfig)) { + migratedConfig[key] = value; + const migration = migrations.find((item) => item.propertyName === key); + migration?.run(); + } + + return migratedConfig; + } + + private static getMigrations( + originalConfig: RenovateConfig, + migratedConfig: RenovateConfig + ): Migration[] { + const migrations: Migration[] = []; + + for (const propertyName of MigrationsService.removedProperties) { + migrations.push( + new RemovePropertyMigration( + propertyName, + originalConfig, + migratedConfig + ) + ); } for (const [ @@ -49,14 +68,24 @@ export class MigrationsService { newPropertyName, ] of MigrationsService.renamedProperties.entries()) { migrations.push( - new ReplacePropertyMigration(oldPropertyName, newPropertyName) + new RenamePropertyMigration( + oldPropertyName, + newPropertyName, + originalConfig, + migratedConfig + ) ); } - for (const migration of migrations) { - config = migration.run(config); - } + migrations.push(new BinarySourceMigration(originalConfig, migratedConfig)); + migrations.push( + new IgnoreNodeModulesMigration(originalConfig, migratedConfig) + ); + migrations.push( + new RequiredStatusChecksMigration(originalConfig, migratedConfig) + ); + migrations.push(new TrustLevelMigration(originalConfig, migratedConfig)); - return config; + return migrations; } } diff --git a/lib/types/migrations/migration.ts b/lib/types/migrations/migration.ts index e64b5ca9a11ed7..93f2035ed60a60 100644 --- a/lib/types/migrations/migration.ts +++ b/lib/types/migrations/migration.ts @@ -1,5 +1,4 @@ -import type { RenovateConfig } from '../../config/types'; - export interface Migration { - run(config: RenovateConfig): RenovateConfig; + readonly propertyName: string; + run(): void; } From 659292a2fdd556531a7246b28ad70694fcf6a440 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Wed, 13 Oct 2021 15:51:05 +0200 Subject: [PATCH 08/16] refactor: migrations --- lib/config/migration.ts | 6 ---- .../custom/binary-source-migration.spec.ts | 15 +++++++++ .../ignore-node-modules-migration.spec.ts | 18 ++++++++++ .../custom/trust-level-migration.spec.ts | 33 +++++++++++++++++++ .../custom/trust-level-migration.ts | 9 +++-- lib/config/migrations/migrations-service.ts | 2 ++ 6 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 lib/config/migrations/custom/binary-source-migration.spec.ts create mode 100644 lib/config/migrations/custom/ignore-node-modules-migration.spec.ts create mode 100644 lib/config/migrations/custom/trust-level-migration.spec.ts diff --git a/lib/config/migration.ts b/lib/config/migration.ts index 058be97a6a946f..d4d71534a45b73 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -262,9 +262,6 @@ export function migrateConfig( } } delete migratedConfig.unpublishSafe; - } else if (key === 'versionScheme') { - migratedConfig.versioning = val; - delete migratedConfig.versionScheme; } else if ( key === 'automergeType' && is.string(val) && @@ -322,9 +319,6 @@ export function migrateConfig( migratedConfig.packages ); delete migratedConfig.packages; - } else if (key === 'excludedPackageNames') { - migratedConfig.excludePackageNames = val; - delete migratedConfig.excludedPackageNames; } else if (key === 'packageName') { migratedConfig.packageNames = [val]; delete migratedConfig.packageName; diff --git a/lib/config/migrations/custom/binary-source-migration.spec.ts b/lib/config/migrations/custom/binary-source-migration.spec.ts new file mode 100644 index 00000000000000..c735ce3f609a11 --- /dev/null +++ b/lib/config/migrations/custom/binary-source-migration.spec.ts @@ -0,0 +1,15 @@ +import type { RenovateConfig } from '../../types'; +import { BinarySourceMigration } from './binary-source-migration'; + +describe('config/migrations/custom/binary-source-migration', () => { + it('should migrate "auto" to "global"', () => { + const originalConfig: Partial = { + binarySource: 'auto', + }; + const migratedConfig: Partial = {}; + const migration = new BinarySourceMigration(originalConfig, migratedConfig); + migration.run(); + + expect(migratedConfig.binarySource).toBe('global'); + }); +}); diff --git a/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts b/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts new file mode 100644 index 00000000000000..ebfa03df568761 --- /dev/null +++ b/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts @@ -0,0 +1,18 @@ +import type { RenovateConfig } from '../../types'; +import { IgnoreNodeModulesMigration } from './ignore-node-modules-migration'; + +describe('config/migrations/custom/ignore-node-modules-migration', () => { + it('should migrate to ignorePaths', () => { + const originalConfig: Partial = { + ignoreNodeModules: true, + }; + const migratedConfig: Partial = {}; + const migration = new IgnoreNodeModulesMigration( + originalConfig, + migratedConfig + ); + migration.run(); + + expect(migratedConfig.ignorePaths).toEqual(['node_modules/']); + }); +}); diff --git a/lib/config/migrations/custom/trust-level-migration.spec.ts b/lib/config/migrations/custom/trust-level-migration.spec.ts new file mode 100644 index 00000000000000..8b952b81d0542e --- /dev/null +++ b/lib/config/migrations/custom/trust-level-migration.spec.ts @@ -0,0 +1,33 @@ +import type { RenovateConfig } from '../../types'; +import { TrustLevelMigration } from './trust-level-migration'; + +describe('config/migrations/custom/trust-level-migration', () => { + it('should handle hight level', () => { + const originalConfig: Partial = { + trustLevel: 'high', + }; + const migratedConfig: Partial = {}; + const migration = new TrustLevelMigration(originalConfig, migratedConfig); + migration.run(); + + expect(migratedConfig.allowCustomCrateRegistries).toBeTrue(); + expect(migratedConfig.allowScripts).toBeTrue(); + expect(migratedConfig.exposeAllEnv).toBeTrue(); + }); + + it('should not rewrite provided properties', () => { + const originalConfig: Partial = { + allowCustomCrateRegistries: false, + allowScripts: false, + exposeAllEnv: false, + trustLevel: 'high', + }; + const migratedConfig: Partial = {}; + const migration = new TrustLevelMigration(originalConfig, migratedConfig); + migration.run(); + + expect(migratedConfig.allowCustomCrateRegistries).toBeFalse(); + expect(migratedConfig.allowScripts).toBeFalse(); + expect(migratedConfig.exposeAllEnv).toBeFalse(); + }); +}); diff --git a/lib/config/migrations/custom/trust-level-migration.ts b/lib/config/migrations/custom/trust-level-migration.ts index 846cb8b8ee3cb0..b9e09077f45739 100644 --- a/lib/config/migrations/custom/trust-level-migration.ts +++ b/lib/config/migrations/custom/trust-level-migration.ts @@ -10,9 +10,12 @@ export class TrustLevelMigration extends AbstractMigration { this.delete(this.propertyName); if (this.originalConfig.trustLevel === 'high') { - this.migratedConfig.allowCustomCrateRegistries ??= true; - this.migratedConfig.allowScripts ??= true; - this.migratedConfig.exposeAllEnv ??= true; + this.migratedConfig.allowCustomCrateRegistries = + this.originalConfig.allowCustomCrateRegistries ?? true; + this.migratedConfig.allowScripts = + this.originalConfig.allowScripts ?? true; + this.migratedConfig.exposeAllEnv = + this.originalConfig.exposeAllEnv ?? true; } } } diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 599fcc451a501e..cd34cb11146a93 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -29,6 +29,8 @@ export class MigrationsService { ['exposeEnv', 'exposeAllEnv'], ['separatePatchReleases', 'separateMinorPatch'], ['multipleMajorPrs', 'separateMultipleMajor'], + ['excludedPackageNames', 'excludePackageNames'], + ['versionScheme', 'versioning'], ]); static run(originalConfig: RenovateConfig): RenovateConfig { From 1af7fa44dca79f9f3e7a47c290785f6fce44ce41 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Wed, 13 Oct 2021 16:08:10 +0200 Subject: [PATCH 09/16] refactor: add test to check order of properties --- lib/config/migrations/migrations-service.spec.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/config/migrations/migrations-service.spec.ts b/lib/config/migrations/migrations-service.spec.ts index 9c9b658c9e9cae..6379dc238bc228 100644 --- a/lib/config/migrations/migrations-service.spec.ts +++ b/lib/config/migrations/migrations-service.spec.ts @@ -27,4 +27,19 @@ describe('config/migrations/migrations-service', () => { expect(migratedConfig[newPropertyName]).toBe('test'); } }); + + it('should save original order of properties', () => { + const originalConfig: Partial = { + exposeEnv: true, + versionScheme: 'test', + excludedPackageNames: ['test'], + }; + const migratedConfig = MigrationsService.run(originalConfig); + + const mappedProperties = Object.keys(originalConfig).map((property) => + MigrationsService.renamedProperties.get(property) + ); + + expect(mappedProperties).toEqual(Object.keys(migratedConfig)); + }); }); From 8f919a050f0963cdd474d2d7de24faae5baaffc0 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Thu, 14 Oct 2021 00:55:45 +0200 Subject: [PATCH 10/16] refactor: migration of go mod tidy --- lib/config/migration.ts | 7 ---- .../custom/go-mod-tidy-migration.spec.ts | 42 +++++++++++++++++++ .../custom/go-mod-tidy-migration.ts | 21 ++++++++++ lib/config/migrations/migrations-service.ts | 2 + 4 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 lib/config/migrations/custom/go-mod-tidy-migration.spec.ts create mode 100644 lib/config/migrations/custom/go-mod-tidy-migration.ts diff --git a/lib/config/migration.ts b/lib/config/migration.ts index d4d71534a45b73..a3e3e6e978c4cf 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -65,13 +65,6 @@ export function migrateConfig( migratedConfig[newKey] = true; } delete migratedConfig[key]; - } else if (key === 'gomodTidy') { - if (val) { - migratedConfig.postUpdateOptions = - migratedConfig.postUpdateOptions || []; - migratedConfig.postUpdateOptions.push('gomodTidy'); - } - delete migratedConfig.gomodTidy; } else if (key === 'semanticCommits') { if (val === true) { migratedConfig.semanticCommits = 'enabled'; diff --git a/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts new file mode 100644 index 00000000000000..b86cdd58307cca --- /dev/null +++ b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts @@ -0,0 +1,42 @@ +import type { RenovateConfig } from '../../types'; +import { GoModTidyMigration } from './go-mod-tidy-migration'; + +describe('config/migrations/custom/go-mod-tidy-migration', () => { + it('should add postUpdateOptions option when true', () => { + const originalConfig: Partial = { + gomodTidy: true, + postUpdateOptions: ['test'], + }; + const migratedConfig: Partial = {}; + const migration = new GoModTidyMigration(originalConfig, migratedConfig); + migration.run(); + + expect(migratedConfig.gomodTidy).toBeUndefined(); + expect(migratedConfig.postUpdateOptions).toContain('test'); + expect(migratedConfig.postUpdateOptions).toContain('gomodTidy'); + }); + + it('should handle case when postUpdateOptions is not defined ', () => { + const originalConfig: Partial = { + gomodTidy: true, + }; + const migratedConfig: Partial = {}; + const migration = new GoModTidyMigration(originalConfig, migratedConfig); + migration.run(); + + expect(migratedConfig.gomodTidy).toBeUndefined(); + expect(migratedConfig.postUpdateOptions).toContain('gomodTidy'); + }); + + it('should only remove when false', () => { + const originalConfig: Partial = { + gomodTidy: false, + }; + const migratedConfig: Partial = {}; + const migration = new GoModTidyMigration(originalConfig, migratedConfig); + migration.run(); + + expect(migratedConfig.gomodTidy).toBeUndefined(); + expect(migratedConfig.postUpdateOptions).toBeUndefined(); + }); +}); diff --git a/lib/config/migrations/custom/go-mod-tidy-migration.ts b/lib/config/migrations/custom/go-mod-tidy-migration.ts new file mode 100644 index 00000000000000..3e984131cfe2a1 --- /dev/null +++ b/lib/config/migrations/custom/go-mod-tidy-migration.ts @@ -0,0 +1,21 @@ +import type { RenovateConfig } from '../../types'; +import { AbstractMigration } from '../base/abstract-migration'; + +export class GoModTidyMigration extends AbstractMigration { + constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { + super('gomodTidy', originalConfig, migratedConfig); + } + + override run(): void { + const { gomodTidy, postUpdateOptions } = this.originalConfig; + + this.delete(this.propertyName); + + if (gomodTidy) { + this.migratedConfig.postUpdateOptions = Array.isArray(postUpdateOptions) + ? postUpdateOptions + : []; + this.migratedConfig.postUpdateOptions.push('gomodTidy'); + } + } +} diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index cd34cb11146a93..4e71910b6f155f 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -3,6 +3,7 @@ import type { RenovateConfig } from '../types'; import { RemovePropertyMigration } from './base/remove-property-migration'; import { RenamePropertyMigration } from './base/rename-property-migration'; import { BinarySourceMigration } from './custom/binary-source-migration'; +import { GoModTidyMigration } from './custom/go-mod-tidy-migration'; import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration'; import { RequiredStatusChecksMigration } from './custom/required-status-checks-migration'; import { TrustLevelMigration } from './custom/trust-level-migration'; @@ -87,6 +88,7 @@ export class MigrationsService { new RequiredStatusChecksMigration(originalConfig, migratedConfig) ); migrations.push(new TrustLevelMigration(originalConfig, migratedConfig)); + migrations.push(new GoModTidyMigration(originalConfig, migratedConfig)); return migrations; } From f481137be406de84677749a97a6f9c78be50090a Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sun, 17 Oct 2021 20:15:07 +0200 Subject: [PATCH 11/16] refactor: unnecessary Partial modificator --- .../custom/binary-source-migration.spec.ts | 4 ++-- .../migrations/custom/go-mod-tidy-migration.spec.ts | 12 ++++++------ .../custom/ignore-node-modules-migration.spec.ts | 4 ++-- .../custom/required-status-checks-migration.spec.ts | 4 ++-- .../migrations/custom/trust-level-migration.spec.ts | 8 ++++---- lib/config/migrations/migrations-service.spec.ts | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/config/migrations/custom/binary-source-migration.spec.ts b/lib/config/migrations/custom/binary-source-migration.spec.ts index c735ce3f609a11..6ebd9573d87143 100644 --- a/lib/config/migrations/custom/binary-source-migration.spec.ts +++ b/lib/config/migrations/custom/binary-source-migration.spec.ts @@ -3,10 +3,10 @@ import { BinarySourceMigration } from './binary-source-migration'; describe('config/migrations/custom/binary-source-migration', () => { it('should migrate "auto" to "global"', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { binarySource: 'auto', }; - const migratedConfig: Partial = {}; + const migratedConfig: RenovateConfig = {}; const migration = new BinarySourceMigration(originalConfig, migratedConfig); migration.run(); diff --git a/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts index b86cdd58307cca..46db5ab249e2e5 100644 --- a/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts +++ b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts @@ -3,11 +3,11 @@ import { GoModTidyMigration } from './go-mod-tidy-migration'; describe('config/migrations/custom/go-mod-tidy-migration', () => { it('should add postUpdateOptions option when true', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { gomodTidy: true, postUpdateOptions: ['test'], }; - const migratedConfig: Partial = {}; + const migratedConfig: RenovateConfig = {}; const migration = new GoModTidyMigration(originalConfig, migratedConfig); migration.run(); @@ -17,10 +17,10 @@ describe('config/migrations/custom/go-mod-tidy-migration', () => { }); it('should handle case when postUpdateOptions is not defined ', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { gomodTidy: true, }; - const migratedConfig: Partial = {}; + const migratedConfig: RenovateConfig = {}; const migration = new GoModTidyMigration(originalConfig, migratedConfig); migration.run(); @@ -29,10 +29,10 @@ describe('config/migrations/custom/go-mod-tidy-migration', () => { }); it('should only remove when false', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { gomodTidy: false, }; - const migratedConfig: Partial = {}; + const migratedConfig: RenovateConfig = {}; const migration = new GoModTidyMigration(originalConfig, migratedConfig); migration.run(); diff --git a/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts b/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts index ebfa03df568761..6c90003aa6b4ad 100644 --- a/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts +++ b/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts @@ -3,10 +3,10 @@ import { IgnoreNodeModulesMigration } from './ignore-node-modules-migration'; describe('config/migrations/custom/ignore-node-modules-migration', () => { it('should migrate to ignorePaths', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { ignoreNodeModules: true, }; - const migratedConfig: Partial = {}; + const migratedConfig: RenovateConfig = {}; const migration = new IgnoreNodeModulesMigration( originalConfig, migratedConfig diff --git a/lib/config/migrations/custom/required-status-checks-migration.spec.ts b/lib/config/migrations/custom/required-status-checks-migration.spec.ts index 1db005dd0da8e2..ee414aeedc4e8b 100644 --- a/lib/config/migrations/custom/required-status-checks-migration.spec.ts +++ b/lib/config/migrations/custom/required-status-checks-migration.spec.ts @@ -3,10 +3,10 @@ import { RequiredStatusChecksMigration } from './required-status-checks-migratio describe('config/migrations/custom/required-status-checks-migration', () => { it('should migrate requiredStatusChecks=null to ignoreTests=true', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { requiredStatusChecks: null, }; - const migratedConfig: Partial = { + const migratedConfig: RenovateConfig = { requiredStatusChecks: null, }; const migration = new RequiredStatusChecksMigration( diff --git a/lib/config/migrations/custom/trust-level-migration.spec.ts b/lib/config/migrations/custom/trust-level-migration.spec.ts index 8b952b81d0542e..f1b07eff25d1fd 100644 --- a/lib/config/migrations/custom/trust-level-migration.spec.ts +++ b/lib/config/migrations/custom/trust-level-migration.spec.ts @@ -3,10 +3,10 @@ import { TrustLevelMigration } from './trust-level-migration'; describe('config/migrations/custom/trust-level-migration', () => { it('should handle hight level', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { trustLevel: 'high', }; - const migratedConfig: Partial = {}; + const migratedConfig: RenovateConfig = {}; const migration = new TrustLevelMigration(originalConfig, migratedConfig); migration.run(); @@ -16,13 +16,13 @@ describe('config/migrations/custom/trust-level-migration', () => { }); it('should not rewrite provided properties', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { allowCustomCrateRegistries: false, allowScripts: false, exposeAllEnv: false, trustLevel: 'high', }; - const migratedConfig: Partial = {}; + const migratedConfig: RenovateConfig = {}; const migration = new TrustLevelMigration(originalConfig, migratedConfig); migration.run(); diff --git a/lib/config/migrations/migrations-service.spec.ts b/lib/config/migrations/migrations-service.spec.ts index 6379dc238bc228..622f0c6e12cbec 100644 --- a/lib/config/migrations/migrations-service.spec.ts +++ b/lib/config/migrations/migrations-service.spec.ts @@ -4,7 +4,7 @@ import { MigrationsService } from './migrations-service'; describe('config/migrations/migrations-service', () => { it('should remove deprecated properties', () => { for (const property of MigrationsService.removedProperties) { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { [property]: 'test', }; @@ -18,7 +18,7 @@ describe('config/migrations/migrations-service', () => { oldPropertyName, newPropertyName, ] of MigrationsService.renamedProperties.entries()) { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { [oldPropertyName]: 'test', }; @@ -29,7 +29,7 @@ describe('config/migrations/migrations-service', () => { }); it('should save original order of properties', () => { - const originalConfig: Partial = { + const originalConfig: RenovateConfig = { exposeEnv: true, versionScheme: 'test', excludedPackageNames: ['test'], From 6248e791c2f0d64258f8d9c68537da9f985c3c7b Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sun, 17 Oct 2021 20:22:20 +0200 Subject: [PATCH 12/16] refactor: fix by comments --- lib/config/migrations/custom/go-mod-tidy-migration.ts | 6 ++---- lib/config/migrations/custom/trust-level-migration.ts | 9 +++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/config/migrations/custom/go-mod-tidy-migration.ts b/lib/config/migrations/custom/go-mod-tidy-migration.ts index 3e984131cfe2a1..674a9aee896360 100644 --- a/lib/config/migrations/custom/go-mod-tidy-migration.ts +++ b/lib/config/migrations/custom/go-mod-tidy-migration.ts @@ -7,14 +7,12 @@ export class GoModTidyMigration extends AbstractMigration { } override run(): void { - const { gomodTidy, postUpdateOptions } = this.originalConfig; + const { gomodTidy } = this.originalConfig; this.delete(this.propertyName); if (gomodTidy) { - this.migratedConfig.postUpdateOptions = Array.isArray(postUpdateOptions) - ? postUpdateOptions - : []; + this.migratedConfig.postUpdateOptions ??= []; this.migratedConfig.postUpdateOptions.push('gomodTidy'); } } diff --git a/lib/config/migrations/custom/trust-level-migration.ts b/lib/config/migrations/custom/trust-level-migration.ts index b9e09077f45739..846cb8b8ee3cb0 100644 --- a/lib/config/migrations/custom/trust-level-migration.ts +++ b/lib/config/migrations/custom/trust-level-migration.ts @@ -10,12 +10,9 @@ export class TrustLevelMigration extends AbstractMigration { this.delete(this.propertyName); if (this.originalConfig.trustLevel === 'high') { - this.migratedConfig.allowCustomCrateRegistries = - this.originalConfig.allowCustomCrateRegistries ?? true; - this.migratedConfig.allowScripts = - this.originalConfig.allowScripts ?? true; - this.migratedConfig.exposeAllEnv = - this.originalConfig.exposeAllEnv ?? true; + this.migratedConfig.allowCustomCrateRegistries ??= true; + this.migratedConfig.allowScripts ??= true; + this.migratedConfig.exposeAllEnv ??= true; } } } From 324acdc22f3a2ff0084538cf4b5290bf3f3d891a Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sun, 17 Oct 2021 20:27:27 +0200 Subject: [PATCH 13/16] refactor: move Migration to types --- lib/config/migrations/base/abstract-migration.ts | 2 +- lib/config/migrations/migrations-service.ts | 2 +- .../migrations/migration.ts => config/migrations/types.ts} | 0 lib/types/migrations/index.ts | 1 - 4 files changed, 2 insertions(+), 3 deletions(-) rename lib/{types/migrations/migration.ts => config/migrations/types.ts} (100%) delete mode 100644 lib/types/migrations/index.ts diff --git a/lib/config/migrations/base/abstract-migration.ts b/lib/config/migrations/base/abstract-migration.ts index 23ffb5563a70ca..56d6fb7548bf22 100644 --- a/lib/config/migrations/base/abstract-migration.ts +++ b/lib/config/migrations/base/abstract-migration.ts @@ -1,5 +1,5 @@ -import type { Migration } from '../../../types/migrations'; import type { RenovateConfig } from '../../types'; +import type { Migration } from '../types'; export abstract class AbstractMigration implements Migration { readonly propertyName: string; diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index 4e71910b6f155f..aa749fcd6b2e88 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -1,4 +1,3 @@ -import type { Migration } from '../../types/migrations'; import type { RenovateConfig } from '../types'; import { RemovePropertyMigration } from './base/remove-property-migration'; import { RenamePropertyMigration } from './base/rename-property-migration'; @@ -7,6 +6,7 @@ import { GoModTidyMigration } from './custom/go-mod-tidy-migration'; import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration'; import { RequiredStatusChecksMigration } from './custom/required-status-checks-migration'; import { TrustLevelMigration } from './custom/trust-level-migration'; +import type { Migration } from './types'; export class MigrationsService { static readonly removedProperties: ReadonlySet = new Set([ diff --git a/lib/types/migrations/migration.ts b/lib/config/migrations/types.ts similarity index 100% rename from lib/types/migrations/migration.ts rename to lib/config/migrations/types.ts diff --git a/lib/types/migrations/index.ts b/lib/types/migrations/index.ts deleted file mode 100644 index 377ad709ed3e52..00000000000000 --- a/lib/types/migrations/index.ts +++ /dev/null @@ -1 +0,0 @@ -export type { Migration } from './migration'; From 863d8b70f3c5fe1c78448eb085e93748847121b5 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sun, 17 Oct 2021 20:43:46 +0200 Subject: [PATCH 14/16] refactor: fix test --- lib/config/migrations/custom/trust-level-migration.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/config/migrations/custom/trust-level-migration.ts b/lib/config/migrations/custom/trust-level-migration.ts index 846cb8b8ee3cb0..b9e09077f45739 100644 --- a/lib/config/migrations/custom/trust-level-migration.ts +++ b/lib/config/migrations/custom/trust-level-migration.ts @@ -10,9 +10,12 @@ export class TrustLevelMigration extends AbstractMigration { this.delete(this.propertyName); if (this.originalConfig.trustLevel === 'high') { - this.migratedConfig.allowCustomCrateRegistries ??= true; - this.migratedConfig.allowScripts ??= true; - this.migratedConfig.exposeAllEnv ??= true; + this.migratedConfig.allowCustomCrateRegistries = + this.originalConfig.allowCustomCrateRegistries ?? true; + this.migratedConfig.allowScripts = + this.originalConfig.allowScripts ?? true; + this.migratedConfig.exposeAllEnv = + this.originalConfig.exposeAllEnv ?? true; } } } From b7c5451b6b866579714248d8d2c3a1a061e5925a Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Sun, 31 Oct 2021 16:04:04 +0100 Subject: [PATCH 15/16] refactor: fix unit tests --- .../base/remove-property-migration.spec.ts | 21 ---------------- .../base/rename-property-migration.spec.ts | 23 ------------------ .../custom/binary-source-migration.spec.ts | 10 +++----- .../custom/go-mod-tidy-migration.spec.ts | 24 ++++++------------- .../custom/go-mod-tidy-migration.ts | 4 ++-- .../ignore-node-modules-migration.spec.ts | 13 +++------- .../required-status-checks-migration.spec.ts | 15 +++--------- .../custom/trust-level-migration.spec.ts | 17 ++++--------- lib/config/migrations/migrations-service.ts | 2 +- 9 files changed, 24 insertions(+), 105 deletions(-) delete mode 100644 lib/config/migrations/base/remove-property-migration.spec.ts delete mode 100644 lib/config/migrations/base/rename-property-migration.spec.ts diff --git a/lib/config/migrations/base/remove-property-migration.spec.ts b/lib/config/migrations/base/remove-property-migration.spec.ts deleted file mode 100644 index f319f0eb4ddafc..00000000000000 --- a/lib/config/migrations/base/remove-property-migration.spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { RenovateConfig } from '../../types'; -import { RemovePropertyMigration } from './remove-property-migration'; - -describe('config/migrations/base/remove-property-migration', () => { - it('should remove property from configuration', () => { - const originalConfig: RenovateConfig = { - test: 'test', - }; - const migratedConfig: RenovateConfig = { - test: 'test', - }; - const migration = new RemovePropertyMigration( - 'test', - originalConfig, - migratedConfig - ); - migration.run(); - - expect(migratedConfig.test).toBeUndefined(); - }); -}); diff --git a/lib/config/migrations/base/rename-property-migration.spec.ts b/lib/config/migrations/base/rename-property-migration.spec.ts deleted file mode 100644 index 06fea2aa6e7218..00000000000000 --- a/lib/config/migrations/base/rename-property-migration.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { RenovateConfig } from '../../types'; -import { RenamePropertyMigration } from './rename-property-migration'; - -describe('config/migrations/base/rename-property-migration', () => { - it('should rename property', () => { - const originalConfig: RenovateConfig = { - old: 'test', - }; - const migratedConfig: RenovateConfig = { - old: 'test', - }; - const migration = new RenamePropertyMigration( - 'old', - 'new', - originalConfig, - migratedConfig - ); - migration.run(); - - expect(migratedConfig.old).toBeUndefined(); - expect(migratedConfig.new).toBe('test'); - }); -}); diff --git a/lib/config/migrations/custom/binary-source-migration.spec.ts b/lib/config/migrations/custom/binary-source-migration.spec.ts index 6ebd9573d87143..22ef956ba40e2b 100644 --- a/lib/config/migrations/custom/binary-source-migration.spec.ts +++ b/lib/config/migrations/custom/binary-source-migration.spec.ts @@ -1,14 +1,10 @@ -import type { RenovateConfig } from '../../types'; -import { BinarySourceMigration } from './binary-source-migration'; +import { MigrationsService } from '../migrations-service'; describe('config/migrations/custom/binary-source-migration', () => { it('should migrate "auto" to "global"', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ binarySource: 'auto', - }; - const migratedConfig: RenovateConfig = {}; - const migration = new BinarySourceMigration(originalConfig, migratedConfig); - migration.run(); + }); expect(migratedConfig.binarySource).toBe('global'); }); diff --git a/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts index 46db5ab249e2e5..3b6cda266fd752 100644 --- a/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts +++ b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts @@ -1,15 +1,11 @@ -import type { RenovateConfig } from '../../types'; -import { GoModTidyMigration } from './go-mod-tidy-migration'; +import { MigrationsService } from '../migrations-service'; describe('config/migrations/custom/go-mod-tidy-migration', () => { it('should add postUpdateOptions option when true', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ gomodTidy: true, postUpdateOptions: ['test'], - }; - const migratedConfig: RenovateConfig = {}; - const migration = new GoModTidyMigration(originalConfig, migratedConfig); - migration.run(); + }); expect(migratedConfig.gomodTidy).toBeUndefined(); expect(migratedConfig.postUpdateOptions).toContain('test'); @@ -17,24 +13,18 @@ describe('config/migrations/custom/go-mod-tidy-migration', () => { }); it('should handle case when postUpdateOptions is not defined ', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ gomodTidy: true, - }; - const migratedConfig: RenovateConfig = {}; - const migration = new GoModTidyMigration(originalConfig, migratedConfig); - migration.run(); + }); expect(migratedConfig.gomodTidy).toBeUndefined(); expect(migratedConfig.postUpdateOptions).toContain('gomodTidy'); }); it('should only remove when false', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ gomodTidy: false, - }; - const migratedConfig: RenovateConfig = {}; - const migration = new GoModTidyMigration(originalConfig, migratedConfig); - migration.run(); + }); expect(migratedConfig.gomodTidy).toBeUndefined(); expect(migratedConfig.postUpdateOptions).toBeUndefined(); diff --git a/lib/config/migrations/custom/go-mod-tidy-migration.ts b/lib/config/migrations/custom/go-mod-tidy-migration.ts index 674a9aee896360..b655489da2116a 100644 --- a/lib/config/migrations/custom/go-mod-tidy-migration.ts +++ b/lib/config/migrations/custom/go-mod-tidy-migration.ts @@ -7,12 +7,12 @@ export class GoModTidyMigration extends AbstractMigration { } override run(): void { - const { gomodTidy } = this.originalConfig; + const { gomodTidy, postUpdateOptions } = this.originalConfig; this.delete(this.propertyName); if (gomodTidy) { - this.migratedConfig.postUpdateOptions ??= []; + this.migratedConfig.postUpdateOptions ??= postUpdateOptions ?? []; this.migratedConfig.postUpdateOptions.push('gomodTidy'); } } diff --git a/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts b/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts index 6c90003aa6b4ad..4f2d4d000a8129 100644 --- a/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts +++ b/lib/config/migrations/custom/ignore-node-modules-migration.spec.ts @@ -1,17 +1,10 @@ -import type { RenovateConfig } from '../../types'; -import { IgnoreNodeModulesMigration } from './ignore-node-modules-migration'; +import { MigrationsService } from '../migrations-service'; describe('config/migrations/custom/ignore-node-modules-migration', () => { it('should migrate to ignorePaths', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ ignoreNodeModules: true, - }; - const migratedConfig: RenovateConfig = {}; - const migration = new IgnoreNodeModulesMigration( - originalConfig, - migratedConfig - ); - migration.run(); + }); expect(migratedConfig.ignorePaths).toEqual(['node_modules/']); }); diff --git a/lib/config/migrations/custom/required-status-checks-migration.spec.ts b/lib/config/migrations/custom/required-status-checks-migration.spec.ts index ee414aeedc4e8b..6527e24d34593c 100644 --- a/lib/config/migrations/custom/required-status-checks-migration.spec.ts +++ b/lib/config/migrations/custom/required-status-checks-migration.spec.ts @@ -1,19 +1,10 @@ -import type { RenovateConfig } from '../../types'; -import { RequiredStatusChecksMigration } from './required-status-checks-migration'; +import { MigrationsService } from '../migrations-service'; describe('config/migrations/custom/required-status-checks-migration', () => { it('should migrate requiredStatusChecks=null to ignoreTests=true', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ requiredStatusChecks: null, - }; - const migratedConfig: RenovateConfig = { - requiredStatusChecks: null, - }; - const migration = new RequiredStatusChecksMigration( - originalConfig, - migratedConfig - ); - migration.run(); + }); expect(migratedConfig.requiredStatusChecks).toBeUndefined(); expect(migratedConfig.ignoreTests).toBeTrue(); diff --git a/lib/config/migrations/custom/trust-level-migration.spec.ts b/lib/config/migrations/custom/trust-level-migration.spec.ts index f1b07eff25d1fd..5fac9753ea1fba 100644 --- a/lib/config/migrations/custom/trust-level-migration.spec.ts +++ b/lib/config/migrations/custom/trust-level-migration.spec.ts @@ -1,14 +1,10 @@ -import type { RenovateConfig } from '../../types'; -import { TrustLevelMigration } from './trust-level-migration'; +import { MigrationsService } from '../migrations-service'; describe('config/migrations/custom/trust-level-migration', () => { it('should handle hight level', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ trustLevel: 'high', - }; - const migratedConfig: RenovateConfig = {}; - const migration = new TrustLevelMigration(originalConfig, migratedConfig); - migration.run(); + }); expect(migratedConfig.allowCustomCrateRegistries).toBeTrue(); expect(migratedConfig.allowScripts).toBeTrue(); @@ -16,15 +12,12 @@ describe('config/migrations/custom/trust-level-migration', () => { }); it('should not rewrite provided properties', () => { - const originalConfig: RenovateConfig = { + const migratedConfig = MigrationsService.run({ allowCustomCrateRegistries: false, allowScripts: false, exposeAllEnv: false, trustLevel: 'high', - }; - const migratedConfig: RenovateConfig = {}; - const migration = new TrustLevelMigration(originalConfig, migratedConfig); - migration.run(); + }); expect(migratedConfig.allowCustomCrateRegistries).toBeFalse(); expect(migratedConfig.allowScripts).toBeFalse(); diff --git a/lib/config/migrations/migrations-service.ts b/lib/config/migrations/migrations-service.ts index aa749fcd6b2e88..d1cee89acb423a 100644 --- a/lib/config/migrations/migrations-service.ts +++ b/lib/config/migrations/migrations-service.ts @@ -42,7 +42,7 @@ export class MigrationsService { ); for (const [key, value] of Object.entries(originalConfig)) { - migratedConfig[key] = value; + migratedConfig[key] ??= value; const migration = migrations.find((item) => item.propertyName === key); migration?.run(); } From 3b808daf5a4d4cb6361697e0422264554a2347d3 Mon Sep 17 00:00:00 2001 From: Maksim Sharipov Date: Tue, 2 Nov 2021 23:56:39 +0100 Subject: [PATCH 16/16] refactor: fix unit tests --- .../migrations/custom/go-mod-tidy-migration.spec.ts | 13 ++++++------- .../custom/required-status-checks-migration.spec.ts | 2 +- lib/config/migrations/migrations-service.spec.ts | 4 ++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts index 3b6cda266fd752..f0c7be274fe469 100644 --- a/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts +++ b/lib/config/migrations/custom/go-mod-tidy-migration.spec.ts @@ -7,9 +7,8 @@ describe('config/migrations/custom/go-mod-tidy-migration', () => { postUpdateOptions: ['test'], }); - expect(migratedConfig.gomodTidy).toBeUndefined(); - expect(migratedConfig.postUpdateOptions).toContain('test'); - expect(migratedConfig.postUpdateOptions).toContain('gomodTidy'); + expect(migratedConfig).not.toHaveProperty('gomodTidy'); + expect(migratedConfig.postUpdateOptions).toEqual(['test', 'gomodTidy']); }); it('should handle case when postUpdateOptions is not defined ', () => { @@ -17,8 +16,8 @@ describe('config/migrations/custom/go-mod-tidy-migration', () => { gomodTidy: true, }); - expect(migratedConfig.gomodTidy).toBeUndefined(); - expect(migratedConfig.postUpdateOptions).toContain('gomodTidy'); + expect(migratedConfig).not.toHaveProperty('gomodTidy'); + expect(migratedConfig.postUpdateOptions).toEqual(['gomodTidy']); }); it('should only remove when false', () => { @@ -26,7 +25,7 @@ describe('config/migrations/custom/go-mod-tidy-migration', () => { gomodTidy: false, }); - expect(migratedConfig.gomodTidy).toBeUndefined(); - expect(migratedConfig.postUpdateOptions).toBeUndefined(); + expect(migratedConfig).not.toHaveProperty('gomodTidy'); + expect(migratedConfig).not.toHaveProperty('postUpdateOptions'); }); }); diff --git a/lib/config/migrations/custom/required-status-checks-migration.spec.ts b/lib/config/migrations/custom/required-status-checks-migration.spec.ts index 6527e24d34593c..2fdd67820869e0 100644 --- a/lib/config/migrations/custom/required-status-checks-migration.spec.ts +++ b/lib/config/migrations/custom/required-status-checks-migration.spec.ts @@ -6,7 +6,7 @@ describe('config/migrations/custom/required-status-checks-migration', () => { requiredStatusChecks: null, }); - expect(migratedConfig.requiredStatusChecks).toBeUndefined(); + expect(migratedConfig).not.toHaveProperty('requiredStatusChecks'); expect(migratedConfig.ignoreTests).toBeTrue(); }); }); diff --git a/lib/config/migrations/migrations-service.spec.ts b/lib/config/migrations/migrations-service.spec.ts index 622f0c6e12cbec..222da9a9ca05ae 100644 --- a/lib/config/migrations/migrations-service.spec.ts +++ b/lib/config/migrations/migrations-service.spec.ts @@ -9,7 +9,7 @@ describe('config/migrations/migrations-service', () => { }; const migratedConfig = MigrationsService.run(originalConfig); - expect(migratedConfig[property]).toBeUndefined(); + expect(migratedConfig).not.toHaveProperty(property); } }); @@ -23,7 +23,7 @@ describe('config/migrations/migrations-service', () => { }; const migratedConfig = MigrationsService.run(originalConfig); - expect(migratedConfig[oldPropertyName]).toBeUndefined(); + expect(migratedConfig).not.toHaveProperty(oldPropertyName); expect(migratedConfig[newPropertyName]).toBe('test'); } });