0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 05:28:35 +00:00
renovatebot_renovate/lib/config/global.ts
RahulGautamSingh 8ec8391310
feat(self-hosted): convert experimental vars to config options (#29137)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
2024-08-19 15:45:49 +00:00

81 lines
2.1 KiB
TypeScript

import type { RenovateConfig, RepoGlobalConfig } from './types';
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: (keyof RepoGlobalConfig)[] = [
'allowedEnv',
'allowCustomCrateRegistries',
'allowedHeaders',
'allowedPostUpgradeCommands',
'allowPlugins',
'allowPostUpgradeCommandTemplating',
'allowScripts',
'binarySource',
'cacheDir',
'cacheHardTtlMinutes',
'cacheTtlOverride',
'containerbaseDir',
'customEnvVariables',
'dockerChildPrefix',
'dockerCliOptions',
'dockerSidecarImage',
'dockerUser',
'dryRun',
'encryptedWarning',
'exposeAllEnv',
'executionTimeout',
'githubTokenWarn',
'localDir',
'migratePresets',
'presetCachePersistence',
'privateKey',
'privateKeyOld',
'gitTimeout',
'platform',
'endpoint',
'httpCacheTtlDays',
'autodiscoverRepoSort',
'autodiscoverRepoOrder',
'userAgent',
'dockerMaxPages',
's3Endpoint',
's3PathStyle',
'cachePrivatePackages',
];
private static config: RepoGlobalConfig = {};
static get(): RepoGlobalConfig;
static get<Key extends keyof RepoGlobalConfig>(
key: Key,
): RepoGlobalConfig[Key];
static get<Key extends keyof RepoGlobalConfig>(
key: Key,
defaultValue: Required<RepoGlobalConfig>[Key],
): Required<RepoGlobalConfig>[Key];
static get<Key extends keyof RepoGlobalConfig>(
key?: Key,
defaultValue?: RepoGlobalConfig[Key],
): RepoGlobalConfig | RepoGlobalConfig[Key] {
return key
? (GlobalConfig.config[key] ?? defaultValue)
: GlobalConfig.config;
}
static set(config: RenovateConfig | RepoGlobalConfig): RenovateConfig {
GlobalConfig.reset();
const result = { ...config };
for (const option of GlobalConfig.OPTIONS) {
GlobalConfig.config[option] = config[option] as never;
delete result[option];
}
return result;
}
static reset(): void {
GlobalConfig.config = {};
}
}