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');
return null;
}
if (!datasources[purl.type]) {
logger.warn({ purlStr }, 'Unknown purl type: ' + purl.type);
if (!datasources[purl.datasource]) {
logger.warn({ purlStr }, 'Unknown purl type: ' + purl.datasource);
return null;
}
const dep = await datasources[purl.type].getPkgReleases(purl, config);
const dep = await datasources[purl.datasource].getPkgReleases(purl, config);
addMetaData(purl, dep);
return dep;
}
function supportsDigests(purlStr) {
const purl = parse(purlStr);
return !!datasources[purl.type].getDigest;
return !!datasources[purl.datasource].getDigest;
}
function getDigest(config, value) {
const purl = parse(config.purl);
return datasources[purl.type].getDigest(config, value);
return datasources[purl.datasource].getDigest(config, value);
}
module.exports = {

View file

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

View file

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

View file

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