renovate/lib/config/index.ts

73 lines
1.8 KiB
TypeScript
Raw Normal View History

import { logger } from '../logger';
import { allManagersList, get } from '../modules/manager';
import * as options from './options';
import type {
AllConfig,
ManagerConfig,
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 = {
2019-08-23 13:46:31 +00:00
...config,
manager,
2019-08-23 13:46:31 +00:00
};
const categories = get(manager, 'categories');
if (categories) {
managerConfig.categories = categories;
}
2023-08-15 09:31:15 +00:00
// TODO: fix types #22198
managerConfig = mergeChildConfig(managerConfig, config[manager] as any);
for (const i of allManagersList) {
delete managerConfig[i];
}
return managerConfig;
}
export function removeGlobalConfig(
config: RenovateConfig,
keepInherited: boolean,
): RenovateConfig {
const outputConfig: RenovateConfig = { ...config };
for (const option of options.getOptions()) {
if (keepInherited && option.inheritConfigSupport) {
continue;
}
if (option.globalOnly) {
delete outputConfig[option.name];
}
}
return outputConfig;
}
2019-08-23 13:46:31 +00:00
export function filterConfig(
2021-06-02 09:25:10 +00:00
inputConfig: AllConfig,
targetStage: RenovateConfigStage,
2021-06-02 09:25:10 +00:00
): AllConfig {
logger.trace({ config: inputConfig }, `filterConfig('${targetStage}')`);
2019-08-23 13:46:31 +00:00
const outputConfig: RenovateConfig = { ...inputConfig };
const stages: (string | undefined)[] = [
'global',
'inherit',
'repository',
'package',
'branch',
'pr',
];
const targetIndex = stages.indexOf(targetStage);
for (const option of options.getOptions()) {
const optionIndex = stages.indexOf(option.stage);
if (optionIndex !== -1 && optionIndex < targetIndex) {
delete outputConfig[option.name];
}
}
return outputConfig;
}