-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): migrate inline with the same sort (#12091)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de> Co-authored-by: Rhys Arkins <rhys@arkins.net>
- Loading branch information
1 parent
e307f18
commit 5377b1f
Showing
21 changed files
with
382 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { RenovateConfig } from '../../types'; | ||
import type { Migration } 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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AbstractMigration } from './abstract-migration'; | ||
|
||
export class RemovePropertyMigration extends AbstractMigration { | ||
override run(): void { | ||
this.delete(this.propertyName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lib/config/migrations/custom/binary-source-migration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { MigrationsService } from '../migrations-service'; | ||
|
||
describe('config/migrations/custom/binary-source-migration', () => { | ||
it('should migrate "auto" to "global"', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
binarySource: 'auto', | ||
}); | ||
|
||
expect(migratedConfig.binarySource).toBe('global'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { RenovateConfig } from '../../types'; | ||
import { AbstractMigration } from '../base/abstract-migration'; | ||
|
||
export class BinarySourceMigration extends AbstractMigration { | ||
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { | ||
super('binarySource', originalConfig, migratedConfig); | ||
} | ||
|
||
override run(): void { | ||
if (this.originalConfig.binarySource === 'auto') { | ||
this.migratedConfig.binarySource = 'global'; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
lib/config/migrations/custom/go-mod-tidy-migration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { MigrationsService } from '../migrations-service'; | ||
|
||
describe('config/migrations/custom/go-mod-tidy-migration', () => { | ||
it('should add postUpdateOptions option when true', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
gomodTidy: true, | ||
postUpdateOptions: ['test'], | ||
}); | ||
|
||
expect(migratedConfig).not.toHaveProperty('gomodTidy'); | ||
expect(migratedConfig.postUpdateOptions).toEqual(['test', 'gomodTidy']); | ||
}); | ||
|
||
it('should handle case when postUpdateOptions is not defined ', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
gomodTidy: true, | ||
}); | ||
|
||
expect(migratedConfig).not.toHaveProperty('gomodTidy'); | ||
expect(migratedConfig.postUpdateOptions).toEqual(['gomodTidy']); | ||
}); | ||
|
||
it('should only remove when false', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
gomodTidy: false, | ||
}); | ||
|
||
expect(migratedConfig).not.toHaveProperty('gomodTidy'); | ||
expect(migratedConfig).not.toHaveProperty('postUpdateOptions'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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 ??= postUpdateOptions ?? []; | ||
this.migratedConfig.postUpdateOptions.push('gomodTidy'); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lib/config/migrations/custom/ignore-node-modules-migration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { MigrationsService } from '../migrations-service'; | ||
|
||
describe('config/migrations/custom/ignore-node-modules-migration', () => { | ||
it('should migrate to ignorePaths', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
ignoreNodeModules: true, | ||
}); | ||
|
||
expect(migratedConfig.ignorePaths).toEqual(['node_modules/']); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
lib/config/migrations/custom/ignore-node-modules-migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { RenovateConfig } from '../../types'; | ||
import { AbstractMigration } from '../base/abstract-migration'; | ||
|
||
export class IgnoreNodeModulesMigration extends AbstractMigration { | ||
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { | ||
super('ignoreNodeModules', originalConfig, migratedConfig); | ||
} | ||
|
||
override run(): void { | ||
this.delete(this.propertyName); | ||
|
||
this.migratedConfig.ignorePaths = this.originalConfig.ignoreNodeModules | ||
? ['node_modules/'] | ||
: []; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
lib/config/migrations/custom/required-status-checks-migration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { MigrationsService } from '../migrations-service'; | ||
|
||
describe('config/migrations/custom/required-status-checks-migration', () => { | ||
it('should migrate requiredStatusChecks=null to ignoreTests=true', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
requiredStatusChecks: null, | ||
}); | ||
|
||
expect(migratedConfig).not.toHaveProperty('requiredStatusChecks'); | ||
expect(migratedConfig.ignoreTests).toBeTrue(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
lib/config/migrations/custom/required-status-checks-migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { RenovateConfig } from '../../types'; | ||
import { AbstractMigration } from '../base/abstract-migration'; | ||
|
||
export class RequiredStatusChecksMigration extends AbstractMigration { | ||
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) { | ||
super('requiredStatusChecks', originalConfig, migratedConfig); | ||
} | ||
|
||
override run(): void { | ||
this.delete(this.propertyName); | ||
|
||
if (this.originalConfig.requiredStatusChecks === null) { | ||
this.migratedConfig.ignoreTests = true; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/config/migrations/custom/trust-level-migration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { MigrationsService } from '../migrations-service'; | ||
|
||
describe('config/migrations/custom/trust-level-migration', () => { | ||
it('should handle hight level', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
trustLevel: 'high', | ||
}); | ||
|
||
expect(migratedConfig.allowCustomCrateRegistries).toBeTrue(); | ||
expect(migratedConfig.allowScripts).toBeTrue(); | ||
expect(migratedConfig.exposeAllEnv).toBeTrue(); | ||
}); | ||
|
||
it('should not rewrite provided properties', () => { | ||
const migratedConfig = MigrationsService.run({ | ||
allowCustomCrateRegistries: false, | ||
allowScripts: false, | ||
exposeAllEnv: false, | ||
trustLevel: 'high', | ||
}); | ||
|
||
expect(migratedConfig.allowCustomCrateRegistries).toBeFalse(); | ||
expect(migratedConfig.allowScripts).toBeFalse(); | ||
expect(migratedConfig.exposeAllEnv).toBeFalse(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 = | ||
this.originalConfig.allowCustomCrateRegistries ?? true; | ||
this.migratedConfig.allowScripts = | ||
this.originalConfig.allowScripts ?? true; | ||
this.migratedConfig.exposeAllEnv = | ||
this.originalConfig.exposeAllEnv ?? true; | ||
} | ||
} | ||
} |
Oops, something went wrong.