fix(validation): massage config (#28458)

Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
RahulGautamSingh 2024-04-17 10:49:21 +05:45 committed by GitHub
parent 7c598d6d33
commit 0a438657e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View file

@ -0,0 +1,20 @@
import { logger } from '../../../../logger';
import { migrateAndValidateConfig } from './util';
describe('workers/global/config/parse/util', () => {
it('massages config', async () => {
const config = {
packageRules: [
{
description: 'haha',
matchPackageNames: ['name'],
enabled: false,
},
],
};
const migratedConfig = await migrateAndValidateConfig(config, 'global');
expect(migratedConfig?.packageRules?.[0].description).toBeArray();
expect(logger.warn).toHaveBeenCalledTimes(0);
});
});

View file

@ -1,3 +1,5 @@
import { dequal } from 'dequal';
import { massageConfig } from '../../../../config/massage';
import { migrateConfig } from '../../../../config/migration'; import { migrateConfig } from '../../../../config/migration';
import type { RenovateConfig } from '../../../../config/types'; import type { RenovateConfig } from '../../../../config/types';
import { validateConfig } from '../../../../config/validation'; import { validateConfig } from '../../../../config/validation';
@ -14,8 +16,13 @@ export async function migrateAndValidateConfig(
`${configType} needs migrating`, `${configType} needs migrating`,
); );
} }
const massagedConfig = massageConfig(migratedConfig);
// log only if it's changed
if (!dequal(migratedConfig, massagedConfig)) {
logger.trace({ config: massagedConfig }, 'Post-massage config');
}
const { warnings, errors } = await validateConfig('global', migratedConfig); const { warnings, errors } = await validateConfig('global', massagedConfig);
if (warnings.length) { if (warnings.length) {
logger.warn( logger.warn(
@ -27,5 +34,5 @@ export async function migrateAndValidateConfig(
logger.warn({ errors }, `Config validation errors found in ${configType}`); logger.warn({ errors }, `Config validation errors found in ${configType}`);
} }
return migratedConfig; return massagedConfig;
} }