From d0018cbd2db9619825ce5396cee3c7dc1fbf73ed Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 29 Jan 2019 08:52:33 +0100 Subject: [PATCH] refactor: purl.fullname -> lookupName --- lib/datasource/cargo/index.js | 2 +- lib/datasource/docker/index.js | 4 +- lib/datasource/github/index.js | 2 +- lib/datasource/go/index.js | 8 ++-- lib/datasource/metadata.js | 2 +- lib/datasource/npm/releases.js | 2 +- lib/datasource/nuget/index.js | 2 +- lib/datasource/orb/index.js | 2 +- lib/datasource/packagist/index.js | 2 +- lib/datasource/pypi/index.js | 2 +- lib/datasource/readme.md | 4 +- lib/datasource/rubygems/releases.js | 2 +- lib/datasource/terraform/index.js | 2 +- lib/manager/bundler/artifacts.js | 2 +- lib/util/purl.js | 4 +- test/datasource/__snapshots__/go.spec.js.snap | 6 +-- test/datasource/cargo.spec.js | 12 ++--- test/datasource/docker.spec.js | 2 +- test/datasource/npm/index.spec.js | 44 +++++++++---------- test/datasource/rubygems/index.spec.js | 2 +- test/util/__snapshots__/purl.spec.js.snap | 12 ++--- 21 files changed, 60 insertions(+), 60 deletions(-) diff --git a/lib/datasource/cargo/index.js b/lib/datasource/cargo/index.js index 96681bb1d3..8fbdcee6c0 100644 --- a/lib/datasource/cargo/index.js +++ b/lib/datasource/cargo/index.js @@ -5,7 +5,7 @@ module.exports = { }; async function getPkgReleases(purl) { - const { fullname: name } = purl; + const { lookupName: name } = purl; const crateUrl = `https://crates.io/api/v1/crates/${name}`; try { const res = (await got(crateUrl, { diff --git a/lib/datasource/docker/index.js b/lib/datasource/docker/index.js index 3db8dd174e..15426cbb4c 100644 --- a/lib/datasource/docker/index.js +++ b/lib/datasource/docker/index.js @@ -320,9 +320,9 @@ async function getTags(registry, repository) { */ async function getPkgReleases(purl, config = {}) { - const { fullname, qualifiers } = purl; + const { lookupName, qualifiers } = purl; const registry = massageRegistry(qualifiers.registry, config.registryUrls); - const repository = getRepository(fullname, qualifiers.registry); + const repository = getRepository(lookupName, qualifiers.registry); const tags = await getTags(registry, repository); if (!tags) { return null; diff --git a/lib/datasource/github/index.js b/lib/datasource/github/index.js index 30d92fd66e..227c715121 100644 --- a/lib/datasource/github/index.js +++ b/lib/datasource/github/index.js @@ -90,7 +90,7 @@ async function getDigest(config) { */ async function getPkgReleases(purl) { - const { fullname: repo, qualifiers: options } = purl; + const { lookupName: repo, qualifiers: options } = purl; options.ref = options.ref || 'tags'; let versions; const cachedResult = await renovateCache.get( diff --git a/lib/datasource/go/index.js b/lib/datasource/go/index.js index d024d36912..fbc2a08180 100644 --- a/lib/datasource/go/index.js +++ b/lib/datasource/go/index.js @@ -9,7 +9,7 @@ module.exports = { function getGithubPurl(repo) { return { - fullname: repo.replace(/\/$/, ''), + lookupName: repo.replace(/\/$/, ''), qualifiers: {}, }; } @@ -68,7 +68,7 @@ async function getSourcePurl(name) { */ async function getPkgReleases(purl) { - const { fullname: name } = purl; + const { lookupName: name } = purl; logger.trace(`go.getPkgReleases(${name})`); const githubPurl = await getSourcePurl(name); if (githubPurl) { @@ -96,10 +96,10 @@ async function getPkgReleases(purl) { async function getDigest(config) { const purl = parse(config.purl); - const name = purl ? purl.fullname : config.depName; + const name = purl ? purl.lookupName : config.depName; const githubPurl = await getSourcePurl(name); if (githubPurl) { - const githubRepo = githubPurl.fullname; + const githubRepo = githubPurl.lookupName; const digest = await github.getDigest({ ...config, githubRepo }); return digest; } diff --git a/lib/datasource/metadata.js b/lib/datasource/metadata.js index 80c3fb86c2..03fdef982a 100644 --- a/lib/datasource/metadata.js +++ b/lib/datasource/metadata.js @@ -68,7 +68,7 @@ function addMetaData(purl, dep) { if (!dep) { return; } - const depName = purl.fullname.toLowerCase(); + const depName = purl.lookupName.toLowerCase(); if ( manualChangelogUrls[purl.type] && manualChangelogUrls[purl.type][depName] diff --git a/lib/datasource/npm/releases.js b/lib/datasource/npm/releases.js index cb8ad80849..40fb221fe0 100644 --- a/lib/datasource/npm/releases.js +++ b/lib/datasource/npm/releases.js @@ -9,7 +9,7 @@ async function getPkgReleases(purl, config) { if (config && config.npmrc) { setNpmrc(config.npmrc); } - const res = await getDependency(purl.fullname, global.testNpmRetries); + const res = await getDependency(purl.lookupName, global.testNpmRetries); if (res) { res.tags = res['dist-tags']; delete res['dist-tags']; diff --git a/lib/datasource/nuget/index.js b/lib/datasource/nuget/index.js index f111b8f7f0..310dba2cfc 100644 --- a/lib/datasource/nuget/index.js +++ b/lib/datasource/nuget/index.js @@ -7,7 +7,7 @@ module.exports = { }; async function getPkgReleases(purl) { - const { fullname: name } = purl; + const { lookupName: name } = purl; logger.trace(`nuget.getPkgReleases(${name})`); const pkgUrl = `https://api.nuget.org/v3-flatcontainer/${name.toLowerCase()}/index.json`; try { diff --git a/lib/datasource/orb/index.js b/lib/datasource/orb/index.js index 6f7f6b22f8..b974ebb71c 100644 --- a/lib/datasource/orb/index.js +++ b/lib/datasource/orb/index.js @@ -11,7 +11,7 @@ module.exports = { */ async function getPkgReleases(purl) { - const { fullname: dependency } = purl; + const { lookupName: dependency } = purl; logger.debug({ dependency }, 'orb.getPkgReleases()'); const cacheNamespace = 'orb'; const cacheKey = dependency; diff --git a/lib/datasource/packagist/index.js b/lib/datasource/packagist/index.js index 0523ae327d..7238e9fb73 100644 --- a/lib/datasource/packagist/index.js +++ b/lib/datasource/packagist/index.js @@ -244,7 +244,7 @@ async function packageLookup(regUrl, name) { } async function getPkgReleases(purl, config = {}) { - const { fullname: name } = purl; + const { lookupName: name } = purl; const { registryUrls } = config; logger.trace(`getPkgReleases(${name})`); const regUrls = []; diff --git a/lib/datasource/pypi/index.js b/lib/datasource/pypi/index.js index dde5da30ec..4a690047ec 100644 --- a/lib/datasource/pypi/index.js +++ b/lib/datasource/pypi/index.js @@ -28,7 +28,7 @@ function compatibleVersions(releases, compatibility) { async function getPkgReleases(purl, config = {}) { const { compatibility } = config; - const { fullname: depName } = purl; + const { lookupName: depName } = purl; let hostUrls = ['https://pypi.org/pypi/']; if (is.nonEmptyArray(config.registryUrls)) { hostUrls = config.registryUrls; diff --git a/lib/datasource/readme.md b/lib/datasource/readme.md index 011b92cb9b..a126207adf 100644 --- a/lib/datasource/readme.md +++ b/lib/datasource/readme.md @@ -8,10 +8,10 @@ The minimum exported interface for a datasource is a function called `getPkgRele The `purl` object contains: -- `fullname`: the package's full name including scope if present (e.g. `@foo/bar`) +- `lookupName`: the package's full name including scope if present (e.g. `@foo/bar`) - `qualifiers`: optional addition arguments, may contain fields like `registry` -In the simplest case, the datasource only needs to pay attention to `purl.fullname`. +In the simplest case, the datasource only needs to pay attention to `purl.lookupName`. `getPkgReleases` should return an object containing: diff --git a/lib/datasource/rubygems/releases.js b/lib/datasource/rubygems/releases.js index a287cb93e5..e4f756edf4 100644 --- a/lib/datasource/rubygems/releases.js +++ b/lib/datasource/rubygems/releases.js @@ -1,7 +1,7 @@ const { nonEmptyArray } = require('@sindresorhus/is'); const { getDependency } = require('./get'); -async function getPkgReleases({ fullname: dependency }, config = {}) { +async function getPkgReleases({ lookupName: dependency }, config = {}) { const { registryUrls } = config; const registries = nonEmptyArray(registryUrls) ? registryUrls : []; diff --git a/lib/datasource/terraform/index.js b/lib/datasource/terraform/index.js index f9587a821a..4e9cc4b53f 100644 --- a/lib/datasource/terraform/index.js +++ b/lib/datasource/terraform/index.js @@ -14,7 +14,7 @@ module.exports = { */ async function getPkgReleases(purl) { - const { fullname: dependency, qualifiers } = purl; + const { lookupName: dependency, qualifiers } = purl; const registry = qualifiers.registry || 'registry.terraform.io'; logger.debug({ dependency, registry }, 'terraform.getDependencies()'); const cacheNamespace = 'terraform'; diff --git a/lib/manager/bundler/artifacts.js b/lib/manager/bundler/artifacts.js index b8f09b3c4b..6b786f00fb 100644 --- a/lib/manager/bundler/artifacts.js +++ b/lib/manager/bundler/artifacts.js @@ -81,7 +81,7 @@ async function getArtifacts( if (rubyConstraint && isValid(rubyConstraint)) { logger.debug('Found ruby compatibility'); const rubyReleases = await getPkgReleases({ - fullname: 'renovate/ruby', + lookupName: 'renovate/ruby', qualifiers: {}, }); if (rubyReleases && rubyReleases.releases) { diff --git a/lib/util/purl.js b/lib/util/purl.js index 3cfb0caa88..7a112eb6e7 100644 --- a/lib/util/purl.js +++ b/lib/util/purl.js @@ -28,11 +28,11 @@ function parse(input) { [res.type, ...remaining] = parts; if (remaining.length === 1) { [res.name] = remaining; - res.fullname = res.name; + res.lookupName = res.name; } else { res.name = remaining.pop(); res.namespace = remaining.join('/').replace('%40', '@'); - res.fullname = res.namespace + '/' + res.name; + res.lookupName = res.namespace + '/' + res.name; } if (res.qualifiers) { const allQualifiers = res.qualifiers.split('&'); diff --git a/test/datasource/__snapshots__/go.spec.js.snap b/test/datasource/__snapshots__/go.spec.js.snap index 8546528f92..f91037029f 100644 --- a/test/datasource/__snapshots__/go.spec.js.snap +++ b/test/datasource/__snapshots__/go.spec.js.snap @@ -17,19 +17,19 @@ exports[`datasource/go getPkgReleases works for known servers 1`] = ` Array [ Array [ Object { - "fullname": "x/text", + "lookupName": "x/text", "qualifiers": Object {}, }, ], Array [ Object { - "fullname": "x/text", + "lookupName": "x/text", "qualifiers": Object {}, }, ], Array [ Object { - "fullname": "go-x/x", + "lookupName": "go-x/x", "qualifiers": Object {}, }, ], diff --git a/test/datasource/cargo.spec.js b/test/datasource/cargo.spec.js index b3fee5092d..7b3ae701e1 100644 --- a/test/datasource/cargo.spec.js +++ b/test/datasource/cargo.spec.js @@ -14,13 +14,13 @@ describe('datasource/cargo', () => { it('returns null for empty result', async () => { got.mockReturnValueOnce(null); expect( - await getPkgReleases({ fullname: 'non_existent_crate' }) + await getPkgReleases({ lookupName: 'non_existent_crate' }) ).toBeNull(); }); it('returns null for missing fields', async () => { got.mockReturnValueOnce({ crate: {} }); expect( - await getPkgReleases({ fullname: 'non_existent_crate' }) + await getPkgReleases({ lookupName: 'non_existent_crate' }) ).toBeNull(); }); it('returns null for 404', async () => { @@ -29,7 +29,7 @@ describe('datasource/cargo', () => { statusCode: 404, }) ); - expect(await getPkgReleases({ fullname: 'some_crate' })).toBeNull(); + expect(await getPkgReleases({ lookupName: 'some_crate' })).toBeNull(); }); it('throws for 5xx', async () => { got.mockImplementationOnce(() => @@ -39,7 +39,7 @@ describe('datasource/cargo', () => { ); let e; try { - await getPkgReleases({ fullname: 'some_crate' }); + await getPkgReleases({ lookupName: 'some_crate' }); } catch (err) { e = err; } @@ -56,7 +56,7 @@ describe('datasource/cargo', () => { got.mockReturnValueOnce({ body: res1, }); - const res = await getPkgReleases({ fullname: 'libc' }); + const res = await getPkgReleases({ lookupName: 'libc' }); expect(res).toMatchSnapshot(); expect(res).not.toBeNull(); expect(res).toBeDefined(); @@ -65,7 +65,7 @@ describe('datasource/cargo', () => { got.mockReturnValueOnce({ body: res2, }); - const res = await getPkgReleases({ fullname: 'amethyst' }); + const res = await getPkgReleases({ lookupName: 'amethyst' }); expect(res).toMatchSnapshot(); expect(res).not.toBeNull(); expect(res).toBeDefined(); diff --git a/test/datasource/docker.spec.js b/test/datasource/docker.spec.js index 2911670a28..5e3ae5de43 100644 --- a/test/datasource/docker.spec.js +++ b/test/datasource/docker.spec.js @@ -215,7 +215,7 @@ describe('api/docker', () => { it('returns null on error', async () => { got.mockReturnValueOnce({}); const res = await docker.getPkgReleases({ - fullname: 'my/node', + lookupName: 'my/node', qualifiers: {}, }); expect(res).toBe(null); diff --git a/test/datasource/npm/index.spec.js b/test/datasource/npm/index.spec.js index 63ea7f78ff..75e98c83a5 100644 --- a/test/datasource/npm/index.spec.js +++ b/test/datasource/npm/index.spec.js @@ -55,14 +55,14 @@ describe('api/npm', () => { .get('/foobar') .reply(200, missingVersions); global.testNpmRetries = 1; - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toBe(null); }); it('should fetch package info from npm', async () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(200, npmResponse); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toMatchSnapshot(); expect(getRelease(res, '0.0.1').canBeUnpublished).toBe(false); expect(getRelease(res, '0.0.2').canBeUnpublished).toBe(false); @@ -196,7 +196,7 @@ describe('api/npm', () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(200, deprecatedPackage); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toMatchSnapshot(); expect(res.deprecationMessage).toMatchSnapshot(); }); @@ -204,7 +204,7 @@ describe('api/npm', () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(200, npmResponse); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toMatchSnapshot(); }); it('should handle no time', async () => { @@ -212,7 +212,7 @@ describe('api/npm', () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(200, npmResponse); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toMatchSnapshot(); expect(getRelease(res, '0.0.1').canBeUnpublished).toBe(false); expect(getRelease(res, '0.0.2').canBeUnpublished).toBeUndefined(); @@ -224,7 +224,7 @@ describe('api/npm', () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(200, npmResponse); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(getRelease(res, '0.0.1').canBeUnpublished).toBe(false); expect(getRelease(res, '0.0.2').canBeUnpublished).toBe(true); }); @@ -232,14 +232,14 @@ describe('api/npm', () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(401); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toBeNull(); }); it('should return null if lookup fails', async () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(404); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toBeNull(); }); it('should throw error for unparseable', async () => { @@ -252,7 +252,7 @@ describe('api/npm', () => { let e; try { global.testNpmRetries = 1; - await npm.getPkgReleases({ fullname: 'foobar' }); + await npm.getPkgReleases({ lookupName: 'foobar' }); } catch (err) { e = err; } @@ -268,7 +268,7 @@ describe('api/npm', () => { let e; try { global.testNpmRetries = 1; - await npm.getPkgReleases({ fullname: 'foobar' }); + await npm.getPkgReleases({ lookupName: 'foobar' }); } catch (err) { e = err; } @@ -281,7 +281,7 @@ describe('api/npm', () => { let e; try { global.testNpmRetries = 0; - await npm.getPkgReleases({ fullname: 'foobar' }); + await npm.getPkgReleases({ lookupName: 'foobar' }); } catch (err) { e = err; } @@ -294,7 +294,7 @@ describe('api/npm', () => { let e; try { global.testNpmRetries = 0; - await npm.getPkgReleases({ fullname: 'foobar' }); + await npm.getPkgReleases({ lookupName: 'foobar' }); } catch (err) { e = err; } @@ -311,7 +311,7 @@ describe('api/npm', () => { .get('/foobar') .reply(200); global.testNpmRetries = 2; - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toMatchSnapshot(); }); it('should throw error for others', async () => { @@ -320,7 +320,7 @@ describe('api/npm', () => { .reply(451); let e; try { - await npm.getPkgReleases({ fullname: 'foobar' }); + await npm.getPkgReleases({ lookupName: 'foobar' }); } catch (err) { e = err; } @@ -334,7 +334,7 @@ describe('api/npm', () => { nock('https://registry.npmjs.org') .get('/foobar') .reply(200, npmResponse); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toMatchSnapshot(); }); it('should use NPM_TOKEN if provided', async () => { @@ -343,7 +343,7 @@ describe('api/npm', () => { .reply(200, npmResponse); const oldToken = process.env.NPM_TOKEN; process.env.NPM_TOKEN = 'some-token'; - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); process.env.NPM_TOKEN = oldToken; expect(res).toMatchSnapshot(); }); @@ -357,7 +357,7 @@ describe('api/npm', () => { .get('/foobar') .reply(200, npmResponse); const npmrc = 'foo=bar'; - const res = await npm.getPkgReleases({ fullname: 'foobar' }, { npmrc }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }, { npmrc }); expect(res).toMatchSnapshot(); }); it('should cache package info from npm', async () => { @@ -365,15 +365,15 @@ describe('api/npm', () => { .get('/foobar') .reply(200, npmResponse); const npmrc = '//registry.npmjs.org/:_authToken=abcdefghijklmnopqrstuvwxyz'; - const res1 = await npm.getPkgReleases({ fullname: 'foobar' }, { npmrc }); - const res2 = await npm.getPkgReleases({ fullname: 'foobar' }, { npmrc }); + const res1 = await npm.getPkgReleases({ lookupName: 'foobar' }, { npmrc }); + const res2 = await npm.getPkgReleases({ lookupName: 'foobar' }, { npmrc }); expect(res1).not.toBe(null); expect(res1).toEqual(res2); }); it('should use global cache', async () => { const dummyValue = 'abc123'; await global.renovateCache.set('datasource-npm', 'foobar', dummyValue, 10); - const res = await npm.getPkgReleases({ fullname: 'foobar' }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }); expect(res).toEqual(dummyValue); }); it('should fetch package info from custom registry', async () => { @@ -383,7 +383,7 @@ describe('api/npm', () => { const npmrc = 'registry=https://npm.mycustomregistry.com/\n//npm.mycustomregistry.com/:_auth = ' + Buffer.from('abcdef').toString('base64'); - const res = await npm.getPkgReleases({ fullname: 'foobar' }, { npmrc }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }, { npmrc }); expect(res).toMatchSnapshot(); }); it('should replace any environment variable in npmrc', async () => { @@ -394,7 +394,7 @@ describe('api/npm', () => { global.trustLevel = 'high'; // eslint-disable-next-line no-template-curly-in-string const npmrc = 'registry=${REGISTRY}'; - const res = await npm.getPkgReleases({ fullname: 'foobar' }, { npmrc }); + const res = await npm.getPkgReleases({ lookupName: 'foobar' }, { npmrc }); expect(res).toMatchSnapshot(); }); it('should throw error if necessary env var is not present', () => { diff --git a/test/datasource/rubygems/index.spec.js b/test/datasource/rubygems/index.spec.js index ec16bd515b..fe493d2097 100644 --- a/test/datasource/rubygems/index.spec.js +++ b/test/datasource/rubygems/index.spec.js @@ -9,7 +9,7 @@ describe('datasource/rubygems', () => { describe('getPkgReleases', () => { const SKIP_CACHE = process.env.RENOVATE_SKIP_CACHE; - const pkg = { fullname: 'rails' }; + const pkg = { lookupName: 'rails' }; const registryUrls = ['https://thirdparty.com', 'https://firstparty.com']; const params = [pkg, { registryUrls }]; diff --git a/test/util/__snapshots__/purl.spec.js.snap b/test/util/__snapshots__/purl.spec.js.snap index 2364379181..a30d63171b 100644 --- a/test/util/__snapshots__/purl.spec.js.snap +++ b/test/util/__snapshots__/purl.spec.js.snap @@ -2,7 +2,7 @@ exports[`util/purl parse() parses namespaced npm 1`] = ` Object { - "fullname": "@foo/bar", + "lookupName": "@foo/bar", "name": "bar", "namespace": "@foo", "qualifiers": Object {}, @@ -12,7 +12,7 @@ Object { exports[`util/purl parse() parses namespaced npm with version 1`] = ` Object { - "fullname": "@foo/bar", + "lookupName": "@foo/bar", "name": "bar", "namespace": "@foo", "qualifiers": Object {}, @@ -23,7 +23,7 @@ Object { exports[`util/purl parse() parses npm with version and 1 qualifier 1`] = ` Object { - "fullname": "foo", + "lookupName": "foo", "name": "foo", "qualifiers": Object { "a": "b", @@ -35,7 +35,7 @@ Object { exports[`util/purl parse() parses npm with version and 2 qualifiers 1`] = ` Object { - "fullname": "foo", + "lookupName": "foo", "name": "foo", "qualifiers": Object { "a": "b", @@ -48,7 +48,7 @@ Object { exports[`util/purl parse() parses npm with version and 2 qualifiers and subpath 1`] = ` Object { - "fullname": "foo", + "lookupName": "foo", "name": "foo", "qualifiers": Object { "a": "b", @@ -62,7 +62,7 @@ Object { exports[`util/purl parse() parses simple npm 1`] = ` Object { - "fullname": "foo", + "lookupName": "foo", "name": "foo", "qualifiers": Object {}, "type": "npm", -- GitLab