2021-04-04 08:58:32 +00:00
|
|
|
import { addStream, logger, setContext } from '../logger';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { get, getLanguageList, getManagerList } from '../manager';
|
2021-03-03 08:40:23 +00:00
|
|
|
import { ensureDir, getSubDirectory, readFile } from '../util/fs';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { ensureTrailingSlash } from '../util/url';
|
2019-08-23 13:46:31 +00:00
|
|
|
import * as cliParser from './cli';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as defaultsParser from './defaults';
|
|
|
|
import * as definitions from './definitions';
|
2019-08-23 13:46:31 +00:00
|
|
|
import * as envParser from './env';
|
2020-05-01 16:03:48 +00:00
|
|
|
import * as fileParser from './file';
|
2021-03-02 20:44:55 +00:00
|
|
|
import type {
|
|
|
|
GlobalConfig,
|
2021-04-20 08:52:57 +00:00
|
|
|
ManagerConfig,
|
2021-03-02 20:44:55 +00:00
|
|
|
RenovateConfig,
|
|
|
|
RenovateConfigStage,
|
|
|
|
} from './types';
|
2019-09-12 06:43:08 +00:00
|
|
|
import { mergeChildConfig } from './utils';
|
2019-08-23 13:46:31 +00:00
|
|
|
|
2019-09-12 06:43:08 +00:00
|
|
|
export { mergeChildConfig };
|
2019-08-23 13:46:31 +00:00
|
|
|
|
|
|
|
export function getManagerConfig(
|
|
|
|
config: RenovateConfig,
|
|
|
|
manager: string
|
|
|
|
): ManagerConfig {
|
|
|
|
let managerConfig: ManagerConfig = {
|
|
|
|
...config,
|
|
|
|
language: null,
|
|
|
|
manager: null,
|
|
|
|
};
|
2018-05-09 06:03:59 +00:00
|
|
|
const language = get(manager, 'language');
|
|
|
|
if (language) {
|
|
|
|
managerConfig = mergeChildConfig(managerConfig, config[language]);
|
|
|
|
}
|
|
|
|
managerConfig = mergeChildConfig(managerConfig, config[manager]);
|
|
|
|
for (const i of getLanguageList().concat(getManagerList())) {
|
|
|
|
delete managerConfig[i];
|
|
|
|
}
|
|
|
|
managerConfig.language = language;
|
|
|
|
managerConfig.manager = manager;
|
|
|
|
return managerConfig;
|
|
|
|
}
|
2017-01-20 13:03:18 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
export async function parseConfigs(
|
|
|
|
env: NodeJS.ProcessEnv,
|
|
|
|
argv: string[]
|
2021-02-05 09:49:34 +00:00
|
|
|
): Promise<GlobalConfig> {
|
2017-01-15 15:12:56 +00:00
|
|
|
logger.debug('Parsing configs');
|
2017-01-14 13:39:26 +00:00
|
|
|
|
2017-01-15 15:12:56 +00:00
|
|
|
// Get configs
|
2021-04-21 07:08:10 +00:00
|
|
|
const defaultConfig = defaultsParser.getConfig();
|
|
|
|
const fileConfig = fileParser.getConfig(env);
|
|
|
|
const cliConfig = cliParser.getConfig(argv);
|
|
|
|
const envConfig = envParser.getConfig(env);
|
2018-06-21 06:43:19 +00:00
|
|
|
|
2021-03-11 07:03:37 +00:00
|
|
|
let config: GlobalConfig = mergeChildConfig(fileConfig, envConfig);
|
2018-06-21 06:43:19 +00:00
|
|
|
config = mergeChildConfig(config, cliConfig);
|
2018-09-13 19:13:52 +00:00
|
|
|
|
|
|
|
const combinedConfig = config;
|
2018-09-10 15:30:03 +00:00
|
|
|
|
|
|
|
config = mergeChildConfig(defaultConfig, config);
|
2017-02-07 20:45:35 +00:00
|
|
|
|
2018-06-21 08:23:59 +00:00
|
|
|
if (config.forceCli) {
|
2020-09-16 14:34:18 +00:00
|
|
|
const forcedCli = { ...cliConfig };
|
|
|
|
delete forcedCli.token;
|
|
|
|
delete forcedCli.hostRules;
|
2020-09-15 08:17:44 +00:00
|
|
|
if (config.force) {
|
2021-03-11 07:03:37 +00:00
|
|
|
config.force = { ...config.force, ...forcedCli };
|
2020-09-15 08:17:44 +00:00
|
|
|
} else {
|
2020-09-16 14:34:18 +00:00
|
|
|
config.force = forcedCli;
|
2020-09-15 08:17:44 +00:00
|
|
|
}
|
2018-06-21 08:23:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-07 06:42:33 +00:00
|
|
|
if (!config.privateKey && config.privateKeyPath) {
|
|
|
|
config.privateKey = await readFile(config.privateKeyPath);
|
|
|
|
delete config.privateKeyPath;
|
|
|
|
}
|
|
|
|
|
2020-02-23 06:31:13 +00:00
|
|
|
if (config.logContext) {
|
|
|
|
// This only has an effect if logContext was defined via file or CLI, otherwise it would already have been detected in env
|
|
|
|
setContext(config.logContext);
|
|
|
|
}
|
|
|
|
|
2017-06-20 19:34:25 +00:00
|
|
|
// Add file logger
|
2018-05-28 14:25:53 +00:00
|
|
|
// istanbul ignore if
|
2017-06-20 19:34:25 +00:00
|
|
|
if (config.logFile) {
|
|
|
|
logger.debug(
|
|
|
|
`Enabling ${config.logFileLevel} logging to ${config.logFile}`
|
|
|
|
);
|
2021-03-03 08:40:23 +00:00
|
|
|
await ensureDir(getSubDirectory(config.logFile));
|
2019-07-15 13:04:03 +00:00
|
|
|
addStream({
|
2017-06-20 19:34:25 +00:00
|
|
|
name: 'logfile',
|
|
|
|
path: config.logFile,
|
|
|
|
level: config.logFileLevel,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-25 05:36:13 +00:00
|
|
|
logger.trace({ config: defaultConfig }, 'Default config');
|
2018-09-13 19:13:52 +00:00
|
|
|
logger.debug({ config: fileConfig }, 'File config');
|
|
|
|
logger.debug({ config: cliConfig }, 'CLI config');
|
|
|
|
logger.debug({ config: envConfig }, 'Env config');
|
|
|
|
logger.debug({ config: combinedConfig }, 'Combined config');
|
2017-01-18 00:48:17 +00:00
|
|
|
|
2017-01-15 15:12:56 +00:00
|
|
|
// Get global config
|
2018-09-10 15:30:03 +00:00
|
|
|
logger.trace({ config }, 'Full config');
|
2017-01-14 13:39:26 +00:00
|
|
|
|
2017-01-15 15:12:56 +00:00
|
|
|
// Print config
|
2017-06-25 05:36:13 +00:00
|
|
|
logger.trace({ config }, 'Global config');
|
2020-01-01 09:23:55 +00:00
|
|
|
|
|
|
|
// Massage endpoint to have a trailing slash
|
|
|
|
if (config.endpoint) {
|
|
|
|
logger.debug('Adding trailing slash to endpoint');
|
2020-04-14 05:05:30 +00:00
|
|
|
config.endpoint = ensureTrailingSlash(config.endpoint);
|
2020-01-01 09:23:55 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 19:34:25 +00:00
|
|
|
// Remove log file entries
|
|
|
|
delete config.logFile;
|
|
|
|
delete config.logFileLevel;
|
2020-01-11 10:22:42 +00:00
|
|
|
|
2017-06-22 07:03:36 +00:00
|
|
|
return config;
|
2017-01-15 15:12:56 +00:00
|
|
|
}
|
2017-01-14 13:39:26 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
export function filterConfig(
|
2021-02-05 09:49:34 +00:00
|
|
|
inputConfig: GlobalConfig,
|
2019-08-23 13:46:31 +00:00
|
|
|
targetStage: RenovateConfigStage
|
2021-02-05 09:49:34 +00:00
|
|
|
): GlobalConfig {
|
2017-07-03 08:31:36 +00:00
|
|
|
logger.trace({ config: inputConfig }, `filterConfig('${targetStage}')`);
|
2019-08-23 13:46:31 +00:00
|
|
|
const outputConfig: RenovateConfig = { ...inputConfig };
|
2018-05-06 09:59:33 +00:00
|
|
|
const stages = ['global', 'repository', 'package', 'branch', 'pr'];
|
2017-07-03 08:31:36 +00:00
|
|
|
const targetIndex = stages.indexOf(targetStage);
|
2017-06-26 11:08:57 +00:00
|
|
|
for (const option of definitions.getOptions()) {
|
2017-07-03 08:31:36 +00:00
|
|
|
const optionIndex = stages.indexOf(option.stage);
|
2017-07-02 07:15:33 +00:00
|
|
|
if (optionIndex !== -1 && optionIndex < targetIndex) {
|
2017-06-27 11:44:03 +00:00
|
|
|
delete outputConfig[option.name];
|
2017-06-26 11:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-27 11:44:03 +00:00
|
|
|
return outputConfig;
|
2017-01-18 13:14:07 +00:00
|
|
|
}
|