2019-07-17 08:14:56 +00:00
|
|
|
import is from '@sindresorhus/is';
|
2019-08-23 13:46:31 +00:00
|
|
|
import { logger } from '../logger';
|
|
|
|
import * as configMassage from './massage';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as configMigration from './migration';
|
2021-03-02 20:44:55 +00:00
|
|
|
import type { RenovateConfig, ValidationMessage } from './types';
|
2019-08-23 13:46:31 +00:00
|
|
|
import * as configValidation from './validation';
|
2019-07-17 08:14:56 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
export async function migrateAndValidate(
|
|
|
|
config: RenovateConfig,
|
|
|
|
input: RenovateConfig
|
|
|
|
): Promise<RenovateConfig> {
|
2017-12-18 08:39:52 +00:00
|
|
|
logger.debug('migrateAndValidate()');
|
2018-03-08 06:28:06 +00:00
|
|
|
try {
|
|
|
|
const { isMigrated, migratedConfig } = configMigration.migrateConfig(input);
|
|
|
|
if (isMigrated) {
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.debug(
|
2018-03-08 06:28:06 +00:00
|
|
|
{ oldConfig: input, newConfig: migratedConfig },
|
|
|
|
'Config migration necessary'
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
logger.debug('No config migration necessary');
|
|
|
|
}
|
|
|
|
const massagedConfig = configMassage.massageConfig(migratedConfig);
|
2018-03-22 12:14:28 +00:00
|
|
|
logger.debug({ config: massagedConfig }, 'massaged config');
|
2019-08-23 13:46:31 +00:00
|
|
|
const {
|
|
|
|
warnings,
|
|
|
|
errors,
|
|
|
|
}: {
|
|
|
|
warnings: ValidationMessage[];
|
|
|
|
errors: ValidationMessage[];
|
|
|
|
} = await configValidation.validateConfig(massagedConfig);
|
2018-03-08 06:28:06 +00:00
|
|
|
// istanbul ignore if
|
2018-09-28 13:20:46 +00:00
|
|
|
if (is.nonEmptyArray(warnings)) {
|
2021-02-02 12:13:13 +00:00
|
|
|
logger.warn({ warnings }, 'Found renovate config warnings');
|
2018-03-08 06:28:06 +00:00
|
|
|
}
|
2018-09-28 13:20:46 +00:00
|
|
|
if (is.nonEmptyArray(errors)) {
|
2018-03-08 06:28:06 +00:00
|
|
|
logger.info({ errors }, 'Found renovate config errors');
|
|
|
|
}
|
|
|
|
massagedConfig.errors = (config.errors || []).concat(errors);
|
|
|
|
if (!config.repoIsOnboarded) {
|
|
|
|
massagedConfig.warnings = (config.warnings || []).concat(warnings);
|
|
|
|
}
|
|
|
|
return massagedConfig;
|
|
|
|
} catch (err) /* istanbul ignore next */ {
|
|
|
|
logger.debug({ config: input }, 'migrateAndValidate error');
|
|
|
|
throw err;
|
2017-11-03 07:25:51 +00:00
|
|
|
}
|
|
|
|
}
|