2021-06-02 10:06:16 +00:00
|
|
|
import { logger } from '../logger';
|
2022-03-03 09:35:26 +00:00
|
|
|
import { get, getLanguageList, getManagerList } from '../modules/manager';
|
2021-08-15 05:25:30 +00:00
|
|
|
import * as options from './options';
|
2022-05-24 07:01:43 +00:00
|
|
|
import type {
|
|
|
|
AllConfig,
|
|
|
|
ManagerConfig,
|
|
|
|
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
|
2022-05-24 07:01:43 +00:00
|
|
|
): ManagerConfig {
|
|
|
|
let managerConfig: ManagerConfig = {
|
2019-08-23 13:46:31 +00:00
|
|
|
...config,
|
|
|
|
language: null,
|
2022-05-24 07:01:43 +00:00
|
|
|
manager,
|
2019-08-23 13:46:31 +00:00
|
|
|
};
|
2018-05-09 06:03:59 +00:00
|
|
|
const language = get(manager, 'language');
|
|
|
|
if (language) {
|
2022-04-24 22:48:54 +00:00
|
|
|
// TODO: fix types #7154
|
|
|
|
managerConfig = mergeChildConfig(managerConfig, config[language] as any);
|
2022-05-24 07:01:43 +00:00
|
|
|
managerConfig.language = language;
|
2018-05-09 06:03:59 +00:00
|
|
|
}
|
2022-04-24 22:48:54 +00:00
|
|
|
// TODO: fix types #7154
|
|
|
|
managerConfig = mergeChildConfig(managerConfig, config[manager] as any);
|
2018-05-09 06:03:59 +00:00
|
|
|
for (const i of getLanguageList().concat(getManagerList())) {
|
|
|
|
delete managerConfig[i];
|
|
|
|
}
|
|
|
|
return managerConfig;
|
|
|
|
}
|
2017-01-20 13:03:18 +00:00
|
|
|
|
2019-08-23 13:46:31 +00:00
|
|
|
export function filterConfig(
|
2021-06-02 09:25:10 +00:00
|
|
|
inputConfig: AllConfig,
|
2019-08-23 13:46:31 +00:00
|
|
|
targetStage: RenovateConfigStage
|
2021-06-02 09:25:10 +00:00
|
|
|
): AllConfig {
|
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 };
|
2022-04-24 22:48:54 +00:00
|
|
|
const stages: (string | undefined)[] = [
|
|
|
|
'global',
|
|
|
|
'repository',
|
|
|
|
'package',
|
|
|
|
'branch',
|
|
|
|
'pr',
|
|
|
|
];
|
2017-07-03 08:31:36 +00:00
|
|
|
const targetIndex = stages.indexOf(targetStage);
|
2021-08-15 05:25:30 +00:00
|
|
|
for (const option of options.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
|
|
|
}
|