-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.ts
155 lines (133 loc) · 4.67 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { addStream, levels, logger, setContext } from '../logger';
import { get, getLanguageList, getManagerList } from '../manager';
import { readFile } from '../util/fs';
import { ensureTrailingSlash } from '../util/url';
import * as cliParser from './cli';
import { RenovateConfig, RenovateConfigStage } from './common';
import * as defaultsParser from './defaults';
import * as definitions from './definitions';
import * as envParser from './env';
import * as fileParser from './file';
import { resolveConfigPresets } from './presets';
import { mergeChildConfig } from './utils';
export * from './common';
export { mergeChildConfig };
export interface ManagerConfig extends RenovateConfig {
language: string;
manager: string;
}
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;
}
export async function parseConfigs(
env: NodeJS.ProcessEnv,
argv: string[]
): Promise<RenovateConfig> {
logger.debug('Parsing configs');
// Get configs
const defaultConfig = await resolveConfigPresets(defaultsParser.getConfig());
const fileConfig = await resolveConfigPresets(fileParser.getConfig(env));
const cliConfig = await resolveConfigPresets(cliParser.getConfig(argv));
const envConfig = await resolveConfigPresets(envParser.getConfig(env));
let config = mergeChildConfig(fileConfig, envConfig);
config = mergeChildConfig(config, cliConfig);
const combinedConfig = config;
config = mergeChildConfig(defaultConfig, config);
if (config.prFooter !== defaultConfig.prFooter) {
config.customPrFooter = true;
}
if (config.forceCli) {
const forcedCli = { ...cliConfig };
delete forcedCli.token;
delete forcedCli.hostRules;
if (config.force) {
config.force = Object.assign(config.force, forcedCli);
} else {
config.force = forcedCli;
}
}
if (!config.privateKey && config.privateKeyPath) {
config.privateKey = await readFile(config.privateKeyPath);
delete config.privateKeyPath;
}
// Deprecated set log level: https://github.com/renovatebot/renovate/issues/8291
// istanbul ignore if
if (config.logLevel) {
logger.warn(
'Configuring logLevel in CLI or file is deprecated. Use LOG_LEVEL environment variable instead'
);
levels('stdout', config.logLevel);
}
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);
}
// Add file logger
// istanbul ignore if
if (config.logFile) {
logger.debug(
`Enabling ${config.logFileLevel} logging to ${config.logFile}`
);
addStream({
name: 'logfile',
path: config.logFile,
level: config.logFileLevel,
});
}
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');
// Get global config
logger.trace({ config }, 'Full config');
// Print config
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);
}
// Remove log file entries
delete config.logFile;
delete config.logFileLevel;
// Move global variables that we need to use later
global.trustLevel =
config.trustLevel || /* istanbul ignore next: never happen? */ 'low';
delete config.trustLevel;
return config;
}
export function filterConfig(
inputConfig: RenovateConfig,
targetStage: RenovateConfigStage
): RenovateConfig {
logger.trace({ config: inputConfig }, `filterConfig('${targetStage}')`);
const outputConfig: RenovateConfig = { ...inputConfig };
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;
}