mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-30 09:17:56 +00:00
36f9d4a185
* refactor: move requireConfig to InheritConfig * fix test * update test * refactor
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import type { GlobalInheritableConfig, RenovateConfig } from './types.ts';
|
|
|
|
export const NOT_PRESENT = Symbol('not-present');
|
|
|
|
export class InheritConfig {
|
|
static OPTIONS: readonly (keyof GlobalInheritableConfig)[] = [
|
|
'bbUseDevelopmentBranch',
|
|
'configFileNames',
|
|
'onboarding',
|
|
'onboardingAutoCloseAge',
|
|
'onboardingBranch',
|
|
'onboardingCommitMessage',
|
|
'onboardingConfig',
|
|
'onboardingConfigFileName',
|
|
'onboardingNoDeps',
|
|
'onboardingPrTitle',
|
|
'requireConfig',
|
|
];
|
|
|
|
private static config: GlobalInheritableConfig = {};
|
|
|
|
static get<Key extends keyof GlobalInheritableConfig>(
|
|
key: Key,
|
|
): GlobalInheritableConfig[Key] | typeof NOT_PRESENT {
|
|
if (key in InheritConfig.config) {
|
|
return InheritConfig.config[key];
|
|
}
|
|
|
|
return NOT_PRESENT;
|
|
}
|
|
|
|
static set(config: RenovateConfig & GlobalInheritableConfig): RenovateConfig {
|
|
InheritConfig.reset();
|
|
|
|
const result = { ...config };
|
|
for (const option of InheritConfig.OPTIONS) {
|
|
if (option in config) {
|
|
InheritConfig.config[option] = config[option] as never;
|
|
}
|
|
delete result[option];
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
static reset(): void {
|
|
InheritConfig.config = {};
|
|
}
|
|
}
|