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

refactor(go): separate getSourcePurl

parent bdf1227b
No related branches found
No related tags found
No related merge requests found
......@@ -5,9 +5,7 @@ module.exports = {
getPkgReleases,
};
async function getPkgReleases(purl, config) {
const { fullname: name } = purl;
logger.trace(`go.getPkgReleases(${name})`);
async function getSourcePurl(name) {
const pkgUrl = 'https://' + name + '?go-get=1';
try {
const res = (await got(pkgUrl, {
......@@ -18,7 +16,7 @@ async function getPkgReleases(purl, config) {
);
if (sourceMatch) {
const [, sourceUrl] = sourceMatch;
logger.debug({ name, sourceUrl }, 'Go lookup sourceUrl');
logger.debug({ depName: name, sourceUrl }, 'Go lookup sourceUrl');
if (sourceUrl && sourceUrl.startsWith('https://github.com/')) {
const githubPurl = {
fullname: sourceUrl
......@@ -26,10 +24,8 @@ async function getPkgReleases(purl, config) {
.replace(/\/$/, ''),
qualifiers: {},
};
const githubTags = await github.getPkgReleases(githubPurl, config);
return githubTags;
return githubPurl;
}
logger.info('Unknown go source: ' + sourceUrl);
} else {
logger.trace({ depName: name }, 'No go-source header found');
}
......@@ -46,3 +42,14 @@ async function getPkgReleases(purl, config) {
return null;
}
}
async function getPkgReleases(purl, config) {
const { fullname: name } = purl;
logger.trace(`go.getPkgReleases(${name})`);
const githubPurl = await getSourcePurl(name);
if (githubPurl) {
const githubTags = await github.getPkgReleases(githubPurl, config);
return githubTags;
}
return null;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment