diff --git a/lib/config/env.js b/lib/config/env.js index ce4e9eb6ea6d7819280032baab2f6c4ded650dc9..bfde0ea98d6e0b67d508cd1e4caef610b80136ee 100644 --- a/lib/config/env.js +++ b/lib/config/env.js @@ -70,5 +70,14 @@ function getConfig(env) { }); } + if (config.platform === 'gitlab') { + config.endpoint = env.GITLAB_ENDPOINT; + } else if (config.platform === 'vsts') { + config.endpoint = 'vsts'; + } else if (env.GITHUB_ENDPOINT) { + // GitHub is default + config.endpoint = env.GITHUB_ENDPOINT; + } + return config; } diff --git a/test/config/__snapshots__/env.spec.js.snap b/test/config/__snapshots__/env.spec.js.snap index bc5ac148e3e8cf3c514f843df2a84ffc4359e259..b1ad17ae5622706f89850d05630a7ce99bab40b7 100644 --- a/test/config/__snapshots__/env.spec.js.snap +++ b/test/config/__snapshots__/env.spec.js.snap @@ -2,22 +2,47 @@ exports[`config/env .getConfig(env) supports GitHub custom endpoint 1`] = ` Object { + "endpoint": "a ghe endpoint", "endpoints": Array [], } `; exports[`config/env .getConfig(env) supports GitHub custom endpoint and github.com 1`] = ` Object { + "endpoint": "a ghe endpoint", "endpoints": Array [ Object { "platform": "github", - "token": "public", + "token": "a github.com token", }, Object { "default": true, - "endpoint": "endpoint", + "endpoint": "a ghe endpoint", "platform": "github", - "token": "token", + "token": "a ghe token", + }, + ], +} +`; + +exports[`config/env .getConfig(env) supports GitHub custom endpoint and github.com and gitlab.com 1`] = ` +Object { + "endpoint": "a ghe endpoint", + "endpoints": Array [ + Object { + "platform": "github", + "token": "a github.com token", + }, + Object { + "default": true, + "endpoint": "a ghe endpoint", + "platform": "github", + "token": "a ghe token", + }, + Object { + "endpoint": undefined, + "platform": "gitlab", + "token": "a gitlab token", }, ], } @@ -30,7 +55,7 @@ Object { "default": true, "endpoint": undefined, "platform": "github", - "token": "token", + "token": "github.com token", }, ], } @@ -38,36 +63,42 @@ Object { exports[`config/env .getConfig(env) supports GitLab custom endpoint 1`] = ` Object { + "endpoint": "a gitlab endpoint", "endpoints": Array [ Object { - "endpoint": "endpoint", + "endpoint": "a gitlab endpoint", "platform": "gitlab", - "token": "token", + "token": "a gitlab token", }, ], + "platform": "gitlab", } `; exports[`config/env .getConfig(env) supports GitLab token 1`] = ` Object { + "endpoint": undefined, "endpoints": Array [ Object { "endpoint": undefined, "platform": "gitlab", - "token": "token", + "token": "a gitlab.com token", }, ], + "platform": "gitlab", } `; exports[`config/env .getConfig(env) supports VSTS 1`] = ` Object { + "endpoint": "vsts", "endpoints": Array [ Object { - "endpoint": "endpoint", + "endpoint": "a vsts endpoint", "platform": "vsts", - "token": undefined, + "token": "a vsts token", }, ], + "platform": "vsts", } `; diff --git a/test/config/env.spec.js b/test/config/env.spec.js index c68cfac4955aef975945c660199df9e00155f45c..e37bc6c67eed91eafdd4ce4e788e8c7cfca545d1 100644 --- a/test/config/env.spec.js +++ b/test/config/env.spec.js @@ -35,32 +35,51 @@ describe('config/env', () => { expect(env.getConfig(envParam).lockFileMaintenance).toEqual({}); }); it('supports GitHub token', () => { - const envParam = { GITHUB_TOKEN: 'token' }; + const envParam = { GITHUB_TOKEN: 'github.com token' }; expect(env.getConfig(envParam)).toMatchSnapshot(); }); it('supports GitHub custom endpoint', () => { - const envParam = { GITHUB_ENDPOINT: 'endpoint' }; + const envParam = { GITHUB_ENDPOINT: 'a ghe endpoint' }; expect(env.getConfig(envParam)).toMatchSnapshot(); }); - it('supports GitHub custom endpoint and github.com', () => { const envParam = { - GITHUB_COM_TOKEN: 'public', - GITHUB_ENDPOINT: 'endpoint', - GITHUB_TOKEN: 'token', + GITHUB_COM_TOKEN: 'a github.com token', + GITHUB_ENDPOINT: 'a ghe endpoint', + GITHUB_TOKEN: 'a ghe token', + }; + expect(env.getConfig(envParam)).toMatchSnapshot(); + }); + it('supports GitHub custom endpoint and github.com and gitlab.com', () => { + const envParam = { + GITHUB_COM_TOKEN: 'a github.com token', + GITHUB_ENDPOINT: 'a ghe endpoint', + GITHUB_TOKEN: 'a ghe token', + GITLAB_TOKEN: 'a gitlab token', }; expect(env.getConfig(envParam)).toMatchSnapshot(); }); it('supports GitLab token', () => { - const envParam = { GITLAB_TOKEN: 'token' }; + const envParam = { + RENOVATE_PLATFORM: 'gitlab', + GITLAB_TOKEN: 'a gitlab.com token', + }; expect(env.getConfig(envParam)).toMatchSnapshot(); }); it('supports GitLab custom endpoint', () => { - const envParam = { GITLAB_TOKEN: 'token', GITLAB_ENDPOINT: 'endpoint' }; + const envParam = { + RENOVATE_PLATFORM: 'gitlab', + GITLAB_TOKEN: 'a gitlab token', + GITLAB_ENDPOINT: 'a gitlab endpoint', + }; expect(env.getConfig(envParam)).toMatchSnapshot(); }); it('supports VSTS', () => { - const envParam = { VSTS_TOKEN: 'token', VSTS_ENDPOINT: 'endpoint' }; + const envParam = { + RENOVATE_PLATFORM: 'vsts', + VSTS_TOKEN: 'a vsts token', + VSTS_ENDPOINT: 'a vsts endpoint', + }; expect(env.getConfig(envParam)).toMatchSnapshot(); }); });