From c59a9fdeb541812a2f0336b597550b4f964117ec Mon Sep 17 00:00:00 2001 From: Kyle Hornberg <khornberg@users.noreply.github.com> Date: Thu, 12 Jul 2018 23:22:04 -0500 Subject: [PATCH] feat(pip): use PIP_INDEX_URL for repository url (#2240) Adds support for PIP_INDEX_URL from environmental variables for self hosted version. This is used instead of any urls set in the config. --- lib/datasource/pypi.js | 3 +++ test/datasource/__snapshots__/pypi.spec.js.snap | 11 +++++++++++ test/datasource/pypi.spec.js | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/datasource/pypi.js b/lib/datasource/pypi.js index 8c1a3bab90..24c30ef10e 100644 --- a/lib/datasource/pypi.js +++ b/lib/datasource/pypi.js @@ -17,6 +17,9 @@ async function getDependency(purl, config = {}) { if (!is.empty(config.registryUrls)) { [hostUrl] = config.registryUrls; } + if (process.env.PIP_INDEX_URL) { + [hostUrl] = [process.env.PIP_INDEX_URL]; + } const lookupUrl = url.resolve(hostUrl, `${depName}/json`); try { const dependency = {}; diff --git a/test/datasource/__snapshots__/pypi.spec.js.snap b/test/datasource/__snapshots__/pypi.spec.js.snap index 1ef2c12495..f627631db7 100644 --- a/test/datasource/__snapshots__/pypi.spec.js.snap +++ b/test/datasource/__snapshots__/pypi.spec.js.snap @@ -113,3 +113,14 @@ Array [ ], ] `; + +exports[`datasource/pypi getDependency supports custom datasource url from environmental variable 1`] = ` +Array [ + Array [ + "https://my.pypi.python/pypi/azure-cli-monitor/json", + Object { + "json": true, + }, + ], +] +`; diff --git a/test/datasource/pypi.spec.js b/test/datasource/pypi.spec.js index d61a953c0e..fc879ddadd 100644 --- a/test/datasource/pypi.spec.js +++ b/test/datasource/pypi.spec.js @@ -39,6 +39,16 @@ describe('datasource/pypi', () => { await datasource.getDependency('pkg:pypi/azure-cli-monitor', config); expect(got.mock.calls).toMatchSnapshot(); }); + it('supports custom datasource url from environmental variable', async () => { + got.mockReturnValueOnce({ + body: JSON.parse(res1), + }); + const pipIndexUrl = process.env.PIP_INDEX_URL; + process.env.PIP_INDEX_URL = 'https://my.pypi.python/pypi/'; + await datasource.getDependency('pkg:pypi/azure-cli-monitor'); + expect(got.mock.calls).toMatchSnapshot(); + process.env.PIP_INDEX_URL = pipIndexUrl; + }); it('returns non-github home_page', async () => { got.mockReturnValueOnce({ body: { -- GitLab