Skip to content

Commit

Permalink
refactor(config): use enum for config type (#27891)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 13, 2024
1 parent 06d751e commit 49971b9
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 96 deletions.
14 changes: 7 additions & 7 deletions lib/config-validator.ts
Expand Up @@ -17,7 +17,7 @@ import {
let returnVal = 0;

async function validate(
isGlobalConfig: boolean,
configType: 'global' | 'repo',
desc: string,
config: RenovateConfig,
strict: boolean,
Expand All @@ -37,7 +37,7 @@ async function validate(
}
}
const massagedConfig = massageConfig(migratedConfig);
const res = await validateConfig(isGlobalConfig, massagedConfig, isPreset);
const res = await validateConfig(configType, massagedConfig, isPreset);
if (res.errors.length) {
logger.error(
{ file: desc, errors: res.errors },
Expand Down Expand Up @@ -76,7 +76,7 @@ type PackageJson = {
const parsedContent = await getParsedContent(file);
try {
logger.info(`Validating ${file}`);
await validate(true, file, parsedContent, strict);
await validate('global', file, parsedContent, strict);
} catch (err) {
logger.warn({ file, err }, 'File is not valid Renovate config');
returnVal = 1;
Expand All @@ -97,7 +97,7 @@ type PackageJson = {
const parsedContent = await getParsedContent(file);
try {
logger.info(`Validating ${file}`);
await validate(false, file, parsedContent, strict);
await validate('repo', file, parsedContent, strict);
} catch (err) {
logger.warn({ file, err }, 'File is not valid Renovate config');
returnVal = 1;
Expand All @@ -114,7 +114,7 @@ type PackageJson = {
if (pkgJson.renovate) {
logger.info(`Validating package.json > renovate`);
await validate(
false,
'repo',
'package.json > renovate',
pkgJson.renovate,
strict,
Expand All @@ -124,7 +124,7 @@ type PackageJson = {
logger.info(`Validating package.json > renovate-config`);
for (const presetConfig of Object.values(pkgJson['renovate-config'])) {
await validate(
false,
'repo',
'package.json > renovate-config',
presetConfig,
strict,
Expand All @@ -141,7 +141,7 @@ type PackageJson = {
const file = process.env.RENOVATE_CONFIG_FILE ?? 'config.js';
logger.info(`Validating ${file}`);
try {
await validate(true, file, fileConfig, strict);
await validate('global', file, fileConfig, strict);
} catch (err) {
logger.error({ file, err }, 'File is not valid Renovate config');
returnVal = 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/config/migrate-validate.ts
Expand Up @@ -32,7 +32,7 @@ export async function migrateAndValidate(
}: {
warnings: ValidationMessage[];
errors: ValidationMessage[];
} = await configValidation.validateConfig(false, massagedConfig);
} = await configValidation.validateConfig('repo', massagedConfig);
// istanbul ignore if
if (is.nonEmptyArray(warnings)) {
logger.warn({ warnings }, 'Found renovate config warnings');
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/index.spec.ts
Expand Up @@ -30,7 +30,7 @@ describe('config/presets/internal/index', () => {
const config = await resolveConfigPresets(
massageConfig(presetConfig),
);
const res = await validateConfig(false, config, true);
const res = await validateConfig('repo', config, true);
expect(res.errors).toHaveLength(0);
expect(res.warnings).toHaveLength(0);
} catch (err) {
Expand Down

0 comments on commit 49971b9

Please sign in to comment.