renovate/lib/config/global.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

import type { RenovateConfig, RepoGlobalConfig } from './types';
2021-02-05 08:20:47 +00:00
export class GlobalConfig {
// TODO: once global config work is complete, add a test to make sure this list includes all options with globalOnly=true (#9603)
private static readonly OPTIONS = [
'allowCustomCrateRegistries',
'allowedPostUpgradeCommands',
'allowPlugins',
'allowPostUpgradeCommandTemplating',
'allowScripts',
'binarySource',
'cacheDir',
'customEnvVariables',
'dockerChildPrefix',
'dockerImagePrefix',
'dockerUser',
'dryRun',
'exposeAllEnv',
'localDir',
'migratePresets',
'privateKey',
'privateKeyOld',
];
2021-02-05 08:20:47 +00:00
private static config: RepoGlobalConfig = {};
2021-02-05 08:20:47 +00:00
static get(): RepoGlobalConfig;
static get<Key extends keyof RepoGlobalConfig>(
key?: Key
): RepoGlobalConfig[Key];
static get<Key extends keyof RepoGlobalConfig>(
key?: Key
): RepoGlobalConfig | RepoGlobalConfig[Key] {
return key ? GlobalConfig.config[key] : GlobalConfig.config;
2021-02-05 08:20:47 +00:00
}
static set(config: RenovateConfig | RepoGlobalConfig): RenovateConfig {
GlobalConfig.reset();
const result = { ...config };
for (const option of GlobalConfig.OPTIONS) {
GlobalConfig.config[option] = config[option];
delete result[option];
}
return result;
}
static reset(): void {
GlobalConfig.config = {};
}
2021-02-05 08:20:47 +00:00
}