fix(config): Replace '__' to '_' globally when decoding hostRules from env (#10939)

This commit is contained in:
Sergei Zharinov 2021-07-23 14:09:30 +04:00 committed by GitHub
parent 7842ff721b
commit 31785b8742
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -114,6 +114,21 @@ describe(getName(), () => {
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
expect(res.hostRules).toHaveLength(2); expect(res.hostRules).toHaveLength(2);
}); });
it('regression test for #10937', () => {
const envParam: NodeJS.ProcessEnv = {
GIT__TAGS_GITLAB_EXAMPLE__DOMAIN_NET_USERNAME: 'some-user',
GIT__TAGS_GITLAB_EXAMPLE__DOMAIN_NET_PASSWORD: 'some-password',
};
const res = env.getConfig(envParam);
expect(res.hostRules).toMatchObject([
{
hostType: 'git-tags',
matchHost: 'gitlab.example-domain.net',
password: 'some-password',
username: 'some-user',
},
]);
});
it('supports datasource env token', () => { it('supports datasource env token', () => {
const envParam: NodeJS.ProcessEnv = { const envParam: NodeJS.ProcessEnv = {
PYPI_TOKEN: 'some-token', PYPI_TOKEN: 'some-token',

View file

@ -100,7 +100,7 @@ export function getConfig(env: NodeJS.ProcessEnv): AllConfig {
continue; // eslint-disable-line no-continue continue; // eslint-disable-line no-continue
} }
// Double underscore __ is used in place of hyphen - // Double underscore __ is used in place of hyphen -
const splitEnv = envName.toLowerCase().replace('__', '-').split('_'); const splitEnv = envName.toLowerCase().replace(/__/g, '-').split('_');
const hostType = splitEnv.shift(); const hostType = splitEnv.shift();
if (datasources.has(hostType)) { if (datasources.has(hostType)) {
const suffix = splitEnv.pop(); const suffix = splitEnv.pop();