Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): nested packageRules migration #9814

Merged
merged 1 commit into from May 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 41 additions & 9 deletions lib/config/__snapshots__/migration.spec.ts.snap
@@ -1,5 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`config/migration it migrates nested packageRules 1`] = `
Object {
"packageRules": Array [
Object {
"enabled": false,
"matchDepTypes": Array [
"devDependencies",
],
},
Object {
"automerge": true,
"excludePackageNames": Array [
"@types/react-table",
],
"groupName": "definitelyTyped",
"matchPackagePrefixes": Array [
"@types/",
],
},
Object {
"automerge": false,
"excludePackageNames": Array [
"@types/react-table",
],
"matchDepTypes": Array [
"dependencies",
],
},
],
}
`;

exports[`config/migration migrateConfig(config, parentConfig) does not migrate multi days 1`] = `
Object {
"schedule": "after 5:00pm on wednesday and thursday",
Expand Down Expand Up @@ -173,6 +205,15 @@ Object {
],
"versioning": "maven",
},
Object {
"automerge": true,
"matchDepTypes": Array [
"bar",
],
"matchPackageNames": Array [
"foo",
],
},
Object {
"matchDepTypes": Array [
"peerDependencies",
Expand Down Expand Up @@ -204,15 +245,6 @@ Object {
"respectLatest": false,
"schedule": "before 5am on Monday",
},
Object {
"automerge": true,
"matchDepTypes": Array [
"bar",
],
"matchPackageNames": Array [
"foo",
],
},
],
"patch": Object {
"automerge": true,
Expand Down
31 changes: 31 additions & 0 deletions lib/config/migration.spec.ts
Expand Up @@ -628,4 +628,35 @@ describe(getName(), () => {
expect(migratedConfig).toMatchSnapshot();
});
});
it('it migrates nested packageRules', () => {
const config: RenovateConfig = {
packageRules: [
{
matchDepTypes: ['devDependencies'],
enabled: false,
},
{
automerge: true,
excludePackageNames: ['@types/react-table'],
packageRules: [
{
groupName: 'definitelyTyped',
matchPackagePrefixes: ['@types/'],
},
{
matchDepTypes: ['dependencies'],
automerge: false,
},
],
},
],
};
const { isMigrated, migratedConfig } = configMigration.migrateConfig(
config,
defaultConfig
);
expect(isMigrated).toBe(true);
expect(migratedConfig).toMatchSnapshot();
expect(migratedConfig.packageRules).toHaveLength(3);
});
});
20 changes: 5 additions & 15 deletions lib/config/migration.ts
Expand Up @@ -554,7 +554,9 @@ export function migrateConfig(
}
// Migrate nested packageRules
if (is.nonEmptyArray(migratedConfig.packageRules)) {
for (const packageRule of migratedConfig.packageRules) {
const existingRules = migratedConfig.packageRules;
migratedConfig.packageRules = [];
for (const packageRule of existingRules) {
if (is.array(packageRule.packageRules)) {
logger.debug('Flattening nested packageRules');
// merge each subrule and add to the parent list
Expand All @@ -563,22 +565,10 @@ export function migrateConfig(
delete combinedRule.packageRules;
migratedConfig.packageRules.push(combinedRule);
}
// delete the nested packageRules
delete packageRule.packageRules;
// mark the original rule for deletion if it's now pointless
if (
!Object.keys(packageRule).some(
(key) => !key.startsWith('match') && !key.startsWith('exclude')
)
) {
packageRule._delete = true;
}
} else {
migratedConfig.packageRules.push(packageRule);
}
}
// filter out any rules which were marked for deletion in the previous step
migratedConfig.packageRules = migratedConfig.packageRules.filter(
(rule) => !rule._delete
);
}
const isMigrated = !dequal(config, migratedConfig);
if (isMigrated) {
Expand Down