mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
d471ed83f1
Deprecate use of “special” env var like `GITHUB_TOKEN` and instead standardize on `RENOVATE_*` environment variables instead. Closes #2834 BREAKING CHANGE: For GitHub, GitLab, Bitbucket and VSTS you need to migrate `*_ENDPOINT` to `RENOVATE_ENDPOINT`, `*_TOKEN` to `RENOVATE_TOKEN`, and same for `BITBUCKET_USERNAME` and `BITBUCKET_PASSWORD`.
74 lines
1.7 KiB
JavaScript
74 lines
1.7 KiB
JavaScript
const configDefinitions = require('./definitions');
|
|
|
|
module.exports = {
|
|
getEnvName,
|
|
getConfig,
|
|
};
|
|
|
|
function getEnvName(option) {
|
|
if (option.env === false) {
|
|
return '';
|
|
}
|
|
if (option.env) {
|
|
return option.env;
|
|
}
|
|
const nameWithUnderscores = option.name.replace(/([A-Z])/g, '_$1');
|
|
return `RENOVATE_${nameWithUnderscores.toUpperCase()}`;
|
|
}
|
|
|
|
function getConfig(env) {
|
|
const options = configDefinitions.getOptions();
|
|
|
|
const config = { hostRules: [] };
|
|
|
|
const coersions = {
|
|
boolean: val => val === 'true',
|
|
list: val => val.split(',').map(el => el.trim()),
|
|
string: val => val.replace(/\\n/g, '\n'),
|
|
json: val => JSON.parse(val),
|
|
integer: parseInt,
|
|
};
|
|
|
|
options.forEach(option => {
|
|
if (option.env !== false) {
|
|
const envName = getEnvName(option);
|
|
if (env[envName]) {
|
|
const coerce = coersions[option.type];
|
|
config[option.name] = coerce(env[envName]);
|
|
}
|
|
}
|
|
});
|
|
|
|
if (env.GITHUB_COM_TOKEN) {
|
|
config.hostRules.push({
|
|
endpoint: 'https://api.github.com/',
|
|
platform: 'github',
|
|
token: env.GITHUB_COM_TOKEN,
|
|
});
|
|
}
|
|
|
|
if (env.DOCKER_USERNAME && env.DOCKER_PASSWORD) {
|
|
config.hostRules.push({
|
|
platform: 'docker',
|
|
username: env.DOCKER_USERNAME,
|
|
password: env.DOCKER_PASSWORD,
|
|
});
|
|
}
|
|
|
|
// These env vars are deprecated and deleted to make sure they're not used
|
|
const unsupportedEnv = [
|
|
'BITBUCKET_TOKEN',
|
|
'BITBUCKET_USERNAME',
|
|
'BITBUCKET_PASSWORD',
|
|
'GITHUB_ENDPOINT',
|
|
'GITHUB_TOKEN',
|
|
'GITLAB_ENDPOINT',
|
|
'GITLAB_TOKEN',
|
|
'VSTS_ENDPOINT',
|
|
'VSTS_TOKEN',
|
|
];
|
|
// eslint-disable-next-line no-param-reassign
|
|
unsupportedEnv.forEach(val => delete env[val]);
|
|
|
|
return config;
|
|
}
|