renovate/lib/config/index.ts

137 lines
3.9 KiB
TypeScript
Raw Normal View History

import { addStream, logger, setContext } from '../logger';
2020-05-01 16:03:48 +00:00
import { get, getLanguageList, getManagerList } from '../manager';
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,
ManagerConfig,
2021-03-02 20:44:55 +00:00
RenovateConfig,
RenovateConfigStage,
} from './types';
import { mergeChildConfig } from './utils';
2019-08-23 13:46:31 +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,
};
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;
}
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
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
let config: GlobalConfig = mergeChildConfig(fileConfig, envConfig);
2018-06-21 06:43:19 +00:00
config = mergeChildConfig(config, cliConfig);
const combinedConfig = config;
2018-09-10 15:30:03 +00:00
config = mergeChildConfig(defaultConfig, config);
if (config.forceCli) {
const forcedCli = { ...cliConfig };
delete forcedCli.token;
delete forcedCli.hostRules;
if (config.force) {
config.force = { ...config.force, ...forcedCli };
} else {
config.force = forcedCli;
}
}
if (!config.privateKey && config.privateKeyPath) {
config.privateKey = await readFile(config.privateKeyPath);
delete config.privateKeyPath;
}
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}`
);
await ensureDir(getSubDirectory(config.logFile));
addStream({
2017-06-20 19:34:25 +00:00
name: 'logfile',
path: config.logFile,
level: config.logFileLevel,
});
}
Refactor repository worker (#344) * Move to subdir * Downgrade eslint to 3 * Refactor api and config usage * Refactor mergeRenovateJson * Test mergeRenovateJson * getOnboardingStatus tests * Refactor repository structure * Refactor config.logger * Revert "Refactor config.logger" This reverts commit 6d7f81af6ee284d01aab811dab7eb05c2274edf3. * Refactor repository logging * Refactor try/catch * Refactor platform and onboarding * Refactor setNpmrc * Fix github logger * npm api use config.logger * Refactor repo worker logger * Refactor repo worker * Refactor branched upgrades * Repository refactoring * Move some debug logging to trace * Deprecate fileName * Refactor upgrades * Refactor repository logs * More repository log refactoring * Refactor repository location * Revert "Refactor repository location" This reverts commit faecbf29516737a2752de54103c0228b9112a51c. * Fix tests * mergeRenovateJson * Recombine repository worker * Add initApis tests * add detectPackageFiles tests * Add determineRepoUpgrades tests * start groupUpgradesByBranch tests * add test * add test * Finish groupUpgradesByBranch coverage * Test updateBranchesSequentially * Finish repo coverage * Finish branch worker coverage * Finish workers coverage * Fix isPin * Complete workers coverage * Finish helpers coverage * Add gitlab api tests * getBranchStatus tests * test createPr * start getPr testing * getPr * update and merge PR tests * getFile * getFileContent tests * getFileJson tests * createFile * updateFile * createBranch * commitFilesToBranch * update yarn * Update yarn
2017-06-25 05:36:13 +00:00
logger.trace({ config: defaultConfig }, 'Default config');
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-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
Refactor repository worker (#344) * Move to subdir * Downgrade eslint to 3 * Refactor api and config usage * Refactor mergeRenovateJson * Test mergeRenovateJson * getOnboardingStatus tests * Refactor repository structure * Refactor config.logger * Revert "Refactor config.logger" This reverts commit 6d7f81af6ee284d01aab811dab7eb05c2274edf3. * Refactor repository logging * Refactor try/catch * Refactor platform and onboarding * Refactor setNpmrc * Fix github logger * npm api use config.logger * Refactor repo worker logger * Refactor repo worker * Refactor branched upgrades * Repository refactoring * Move some debug logging to trace * Deprecate fileName * Refactor upgrades * Refactor repository logs * More repository log refactoring * Refactor repository location * Revert "Refactor repository location" This reverts commit faecbf29516737a2752de54103c0228b9112a51c. * Fix tests * mergeRenovateJson * Recombine repository worker * Add initApis tests * add detectPackageFiles tests * Add determineRepoUpgrades tests * start groupUpgradesByBranch tests * add test * add test * Finish groupUpgradesByBranch coverage * Test updateBranchesSequentially * Finish repo coverage * Finish branch worker coverage * Finish workers coverage * Fix isPin * Complete workers coverage * Finish helpers coverage * Add gitlab api tests * getBranchStatus tests * test createPr * start getPr testing * getPr * update and merge PR tests * getFile * getFileContent tests * getFileJson tests * createFile * updateFile * createBranch * commitFilesToBranch * update yarn * Update yarn
2017-06-25 05:36:13 +00:00
logger.trace({ config }, 'Global config');
// Massage endpoint to have a trailing slash
if (config.endpoint) {
logger.debug('Adding trailing slash to endpoint');
config.endpoint = ensureTrailingSlash(config.endpoint);
}
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
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 {
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'];
const targetIndex = stages.indexOf(targetStage);
for (const option of definitions.getOptions()) {
const optionIndex = stages.indexOf(option.stage);
if (optionIndex !== -1 && optionIndex < targetIndex) {
delete outputConfig[option.name];
}
}
return outputConfig;
}