refactor: purl.type -> purl.datasource

This commit is contained in:
Rhys Arkins 2019-01-29 09:15:46 +01:00
parent d0018cbd2d
commit 82cc45b2e5
4 changed files with 20 additions and 17 deletions

View file

@ -81,23 +81,23 @@ async function fetchReleases(config) {
logger.info({ purlStr }, 'Cannot parse purl'); logger.info({ purlStr }, 'Cannot parse purl');
return null; return null;
} }
if (!datasources[purl.type]) { if (!datasources[purl.datasource]) {
logger.warn({ purlStr }, 'Unknown purl type: ' + purl.type); logger.warn({ purlStr }, 'Unknown purl type: ' + purl.datasource);
return null; return null;
} }
const dep = await datasources[purl.type].getPkgReleases(purl, config); const dep = await datasources[purl.datasource].getPkgReleases(purl, config);
addMetaData(purl, dep); addMetaData(purl, dep);
return dep; return dep;
} }
function supportsDigests(purlStr) { function supportsDigests(purlStr) {
const purl = parse(purlStr); const purl = parse(purlStr);
return !!datasources[purl.type].getDigest; return !!datasources[purl.datasource].getDigest;
} }
function getDigest(config, value) { function getDigest(config, value) {
const purl = parse(config.purl); const purl = parse(config.purl);
return datasources[purl.type].getDigest(config, value); return datasources[purl.datasource].getDigest(config, value);
} }
module.exports = { module.exports = {

View file

@ -70,13 +70,16 @@ function addMetaData(purl, dep) {
} }
const depName = purl.lookupName.toLowerCase(); const depName = purl.lookupName.toLowerCase();
if ( if (
manualChangelogUrls[purl.type] && manualChangelogUrls[purl.datasource] &&
manualChangelogUrls[purl.type][depName] manualChangelogUrls[purl.datasource][depName]
) { ) {
dep.changelogUrl = manualChangelogUrls[purl.type][depName]; dep.changelogUrl = manualChangelogUrls[purl.datasource][depName];
} }
if (manualSourceUrls[purl.type] && manualSourceUrls[purl.type][depName]) { if (
dep.sourceUrl = manualSourceUrls[purl.type][depName]; manualSourceUrls[purl.datasource] &&
manualSourceUrls[purl.datasource][depName]
) {
dep.sourceUrl = manualSourceUrls[purl.datasource][depName];
} }
if ( if (
!dep.sourceUrl && !dep.sourceUrl &&

View file

@ -25,7 +25,7 @@ function parse(input) {
[remaining, res.version] = parts; [remaining, res.version] = parts;
} }
parts = remaining.split('/'); parts = remaining.split('/');
[res.type, ...remaining] = parts; [res.datasource, ...remaining] = parts;
if (remaining.length === 1) { if (remaining.length === 1) {
[res.name] = remaining; [res.name] = remaining;
res.lookupName = res.name; res.lookupName = res.name;

View file

@ -2,52 +2,53 @@
exports[`util/purl parse() parses namespaced npm 1`] = ` exports[`util/purl parse() parses namespaced npm 1`] = `
Object { Object {
"datasource": "npm",
"lookupName": "@foo/bar", "lookupName": "@foo/bar",
"name": "bar", "name": "bar",
"namespace": "@foo", "namespace": "@foo",
"qualifiers": Object {}, "qualifiers": Object {},
"type": "npm",
} }
`; `;
exports[`util/purl parse() parses namespaced npm with version 1`] = ` exports[`util/purl parse() parses namespaced npm with version 1`] = `
Object { Object {
"datasource": "npm",
"lookupName": "@foo/bar", "lookupName": "@foo/bar",
"name": "bar", "name": "bar",
"namespace": "@foo", "namespace": "@foo",
"qualifiers": Object {}, "qualifiers": Object {},
"type": "npm",
"version": "1.0.0", "version": "1.0.0",
} }
`; `;
exports[`util/purl parse() parses npm with version and 1 qualifier 1`] = ` exports[`util/purl parse() parses npm with version and 1 qualifier 1`] = `
Object { Object {
"datasource": "npm",
"lookupName": "foo", "lookupName": "foo",
"name": "foo", "name": "foo",
"qualifiers": Object { "qualifiers": Object {
"a": "b", "a": "b",
}, },
"type": "npm",
"version": "1.0.0", "version": "1.0.0",
} }
`; `;
exports[`util/purl parse() parses npm with version and 2 qualifiers 1`] = ` exports[`util/purl parse() parses npm with version and 2 qualifiers 1`] = `
Object { Object {
"datasource": "npm",
"lookupName": "foo", "lookupName": "foo",
"name": "foo", "name": "foo",
"qualifiers": Object { "qualifiers": Object {
"a": "b", "a": "b",
"c": "d", "c": "d",
}, },
"type": "npm",
"version": "1.0.0", "version": "1.0.0",
} }
`; `;
exports[`util/purl parse() parses npm with version and 2 qualifiers and subpath 1`] = ` exports[`util/purl parse() parses npm with version and 2 qualifiers and subpath 1`] = `
Object { Object {
"datasource": "npm",
"lookupName": "foo", "lookupName": "foo",
"name": "foo", "name": "foo",
"qualifiers": Object { "qualifiers": Object {
@ -55,16 +56,15 @@ Object {
"c": "d", "c": "d",
}, },
"subpath": "stop", "subpath": "stop",
"type": "npm",
"version": "1.0.0", "version": "1.0.0",
} }
`; `;
exports[`util/purl parse() parses simple npm 1`] = ` exports[`util/purl parse() parses simple npm 1`] = `
Object { Object {
"datasource": "npm",
"lookupName": "foo", "lookupName": "foo",
"name": "foo", "name": "foo",
"qualifiers": Object {}, "qualifiers": Object {},
"type": "npm",
} }
`; `;