Skip to content
Snippets Groups Projects
Commit debc75f3 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor: move lookupType out of qualifiers

parent bf57bb80
No related branches found
No related tags found
No related merge requests found
...@@ -90,8 +90,8 @@ async function getDigest(config) { ...@@ -90,8 +90,8 @@ async function getDigest(config) {
*/ */
async function getPkgReleases(purl) { async function getPkgReleases(purl) {
const { lookupName: repo, qualifiers } = purl; const { lookupName: repo } = purl;
const lookupType = qualifiers.lookupType || 'tags'; const lookupType = purl.lookupType || 'tags';
let versions; let versions;
const cachedResult = await renovateCache.get( const cachedResult = await renovateCache.get(
cacheNamespace, cacheNamespace,
...@@ -102,7 +102,7 @@ async function getPkgReleases(purl) { ...@@ -102,7 +102,7 @@ async function getPkgReleases(purl) {
return cachedResult; return cachedResult;
} }
try { try {
if (lookupType === 'release') { if (lookupType === 'releases') {
const url = `https://api.github.com/repos/${repo}/releases?per_page=100`; const url = `https://api.github.com/repos/${repo}/releases?per_page=100`;
versions = (await ghGot(url, { paginate: true })).body.map( versions = (await ghGot(url, { paginate: true })).body.map(
o => o.tag_name o => o.tag_name
......
...@@ -128,7 +128,7 @@ function extractPackageFile(content) { ...@@ -128,7 +128,7 @@ function extractPackageFile(content) {
dep.depName = depName; dep.depName = depName;
dep.repo = parsedUrl.repo; dep.repo = parsedUrl.repo;
dep.currentValue = parsedUrl.currentValue; dep.currentValue = parsedUrl.currentValue;
dep.purl = 'pkg:github/' + dep.repo + '?lookupType=release'; dep.purl = 'pkg:github/' + dep.repo + '?lookupType=releases';
deps.push(dep); deps.push(dep);
} else { } else {
logger.info( logger.info(
......
...@@ -41,6 +41,10 @@ function parse(input) { ...@@ -41,6 +41,10 @@ function parse(input) {
const [key, val] = qualifier.split('='); const [key, val] = qualifier.split('=');
res.qualifiers[key] = val; res.qualifiers[key] = val;
}); });
if (res.qualifiers.lookupType) {
res.lookupType = res.qualifiers.lookupType;
delete res.qualifiers.lookupType;
}
} else { } else {
res.qualifiers = {}; res.qualifiers = {};
} }
......
...@@ -88,7 +88,7 @@ describe('datasource/github', () => { ...@@ -88,7 +88,7 @@ describe('datasource/github', () => {
]; ];
ghGot.mockReturnValueOnce({ headers: {}, body }); ghGot.mockReturnValueOnce({ headers: {}, body });
const res = await datasource.getPkgReleases({ const res = await datasource.getPkgReleases({
purl: 'pkg:github/some/dep?lookupType=release', purl: 'pkg:github/some/dep?lookupType=releases',
}); });
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
expect(res.releases).toHaveLength(2); expect(res.releases).toHaveLength(2);
......
...@@ -90,7 +90,7 @@ Array [ ...@@ -90,7 +90,7 @@ Array [
", ",
"depName": "io_bazel_rules_go", "depName": "io_bazel_rules_go",
"depType": "http_archive", "depType": "http_archive",
"purl": "pkg:github/bazelbuild/rules_go?lookupType=release", "purl": "pkg:github/bazelbuild/rules_go?lookupType=releases",
"repo": "bazelbuild/rules_go", "repo": "bazelbuild/rules_go",
}, },
Object { Object {
...@@ -107,7 +107,7 @@ Array [ ...@@ -107,7 +107,7 @@ Array [
", ",
"depName": "bazel_skylib", "depName": "bazel_skylib",
"depType": "http_archive", "depType": "http_archive",
"purl": "pkg:github/bazelbuild/bazel-skylib?lookupType=release", "purl": "pkg:github/bazelbuild/bazel-skylib?lookupType=releases",
"repo": "bazelbuild/bazel-skylib", "repo": "bazelbuild/bazel-skylib",
}, },
] ]
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`util/purl parse() parses github with lookupType 1`] = `
Object {
"datasource": "github",
"lookupName": "abc/def",
"lookupType": "releases",
"qualifiers": Object {},
}
`;
exports[`util/purl parse() parses namespaced npm 1`] = ` exports[`util/purl parse() parses namespaced npm 1`] = `
Object { Object {
"datasource": "npm", "datasource": "npm",
......
...@@ -26,5 +26,8 @@ describe('util/purl', () => { ...@@ -26,5 +26,8 @@ describe('util/purl', () => {
it('parses npm with version and 2 qualifiers and subpath', () => { it('parses npm with version and 2 qualifiers and subpath', () => {
expect(parse('pkg:npm/foo@1.0.0?a=b&c=d#stop')).toMatchSnapshot(); expect(parse('pkg:npm/foo@1.0.0?a=b&c=d#stop')).toMatchSnapshot();
}); });
it('parses github with lookupType', () => {
expect(parse('pkg:github/abc/def?lookupType=releases')).toMatchSnapshot();
});
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment