Skip to content

Commit

Permalink
fix(config): migrate language objects (#23157)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
rarkins and viceice committed Jul 5, 2023
1 parent 9bc12da commit 7b82e8d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 31 deletions.
26 changes: 15 additions & 11 deletions lib/config/__snapshots__/migration.spec.ts.snap
Expand Up @@ -172,6 +172,21 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates config 1`
},
"onboarding": false,
"packageRules": [
{
"enabled": false,
"matchCategories": [
"python",
],
"matchPackageNames": [
"foo",
],
},
{
"enabled": false,
"matchCategories": [
"dotnet",
],
},
{
"excludePackageNames": "foo",
"groupName": "angular packages",
Expand Down Expand Up @@ -311,17 +326,6 @@ exports[`config/migration migrateConfig(config, parentConfig) migrates more pack
}
`;
exports[`config/migration migrateConfig(config, parentConfig) migrates node to travis 1`] = `
{
"node": {
"automerge": false,
},
"travis": {
"enabled": true,
},
}
`;
exports[`config/migration migrateConfig(config, parentConfig) migrates packageFiles 1`] = `
{
"includePaths": [
Expand Down
32 changes: 12 additions & 20 deletions lib/config/migration.spec.ts
Expand Up @@ -122,6 +122,9 @@ describe('config/migration', () => {
],
},
],
dotnet: {
enabled: false,
},
exposeEnv: true,
lockFileMaintenance: {
exposeEnv: false,
Expand All @@ -133,6 +136,14 @@ describe('config/migration', () => {
automerge: 'minor',
schedule: null,
},
python: {
packageRules: [
{
matchPackageNames: ['foo'],
enabled: false,
},
],
},
nvmrc: {
pathRules: [
{
Expand All @@ -159,7 +170,7 @@ describe('config/migration', () => {
expect(isMigrated).toBeTrue();
expect(migratedConfig.depTypes).toBeUndefined();
expect(migratedConfig.automerge).toBe(false);
expect(migratedConfig.packageRules).toHaveLength(9);
expect(migratedConfig.packageRules).toHaveLength(11);
expect(migratedConfig.hostRules).toHaveLength(1);
});

Expand Down Expand Up @@ -309,25 +320,6 @@ describe('config/migration', () => {
).toBeFalse();
});

it('migrates node to travis', () => {
const config: TestRenovateConfig = {
node: {
enabled: true,
automerge: 'none' as never,
},
};
const { isMigrated, migratedConfig } =
configMigration.migrateConfig(config);
expect(migratedConfig).toMatchSnapshot();
expect(isMigrated).toBeTrue();
expect(
(migratedConfig.node as RenovateSharedConfig).enabled
).toBeUndefined();
expect((migratedConfig.travis as RenovateSharedConfig).enabled).toBe(
true
);
});

it('migrates packageFiles', () => {
const config: TestRenovateConfig = {
packageFiles: [
Expand Down
24 changes: 24 additions & 0 deletions lib/config/migration.ts
Expand Up @@ -104,6 +104,30 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig {
}
}
}
const languages = [
'docker',
'dotnet',
'golang',
'java',
'js',
'node',
'php',
'python',
'ruby',
'rust',
];
for (const language of languages) {
if (is.nonEmptyObject(migratedConfig[language])) {
migratedConfig.packageRules ??= [];
const currentContent = migratedConfig[language] as any;
const packageRule = {
matchCategories: [language],
...currentContent,
};
migratedConfig.packageRules.unshift(packageRule);
delete migratedConfig[language];
}
}
// Migrate nested packageRules
if (is.nonEmptyArray(migratedConfig.packageRules)) {
const existingRules = migratedConfig.packageRules;
Expand Down

0 comments on commit 7b82e8d

Please sign in to comment.