Skip to content
Snippets Groups Projects
Commit 7d31af5e authored by Ayoub Kaanich's avatar Ayoub Kaanich Committed by Rhys Arkins
Browse files

feat: Support Bazel commit-based go_repository (#2821)

Closes #2806
parent 994e052b
No related merge requests found
const got = require('got');
const github = require('./github');
const { parse } = require('../util/purl');
module.exports = {
getPkgReleases,
......@@ -89,7 +90,9 @@ async function getPkgReleases(purl, config) {
*/
async function getDigest(config) {
const githubPurl = await getSourcePurl(config.depName);
const purl = parse(config.purl);
const name = purl ? purl.fullname : config.depName;
const githubPurl = await getSourcePurl(name);
if (githubPurl) {
const githubRepo = githubPurl.fullname;
const digest = await github.getDigest({ ...config, githubRepo });
......
......@@ -48,6 +48,7 @@ function extractPackageFile(content) {
let importpath;
let remote;
let currentValue;
let commit;
let url;
let sha256;
let match = def.match(/name = "([^"]+)"/);
......@@ -71,6 +72,10 @@ function extractPackageFile(content) {
const urls = match[1].replace(/\s/g, '').split('","');
url = urls.find(parseUrl);
}
match = def.match(/commit = "([^"]+)"/);
if (match) {
[, commit] = match;
}
match = def.match(/sha256 = "([^"]+)"/);
if (match) {
[, sha256] = match;
......@@ -91,11 +96,15 @@ function extractPackageFile(content) {
depType === 'go_repository' &&
depName &&
importpath &&
currentValue
(currentValue || commit)
) {
dep.depName = depName;
dep.currentValue = currentValue;
dep.currentValue = currentValue || commit.substr(0, 7);
dep.purl = 'pkg:go/' + importpath;
if (commit) {
dep.currentDigest = commit;
dep.digestOneAndOnly = true;
}
deps.push(dep);
} else if (
depType === 'http_archive' &&
......
......@@ -13,10 +13,9 @@ async function updateDependency(fileContent, upgrade) {
upgrade.depType === 'git_repository' ||
upgrade.depType === 'go_repository'
) {
newDef = upgrade.def.replace(
/tag = "[^"]+"/,
`tag = "${upgrade.newValue}"`
);
newDef = upgrade.def
.replace(/tag = "[^"]+"/, `tag = "${upgrade.newValue}"`)
.replace(/commit = "[^"]+"/, `commit = "${upgrade.newDigest}"`);
} else if (upgrade.depType === 'http_archive') {
const [, shortRepo] = upgrade.repo.split('/');
const newUrl = `https://github.com/${upgrade.repo}/releases/download/${
......
......@@ -15,6 +15,21 @@ Array [
"purl": "pkg:go/github.com/bitly/go-nsq",
"versionScheme": "semver",
},
Object {
"currentDigest": "dec09d789f3dba190787f8b4454c7d3c936fed9e",
"currentValue": "dec09d7",
"def": "go_repository(
name = \\"com_github_google_uuid\\",
importpath = \\"github.com/google/uuid\\",
commit = \\"dec09d789f3dba190787f8b4454c7d3c936fed9e\\"
)
",
"depName": "com_github_google_uuid",
"depType": "go_repository",
"digestOneAndOnly": true,
"purl": "pkg:go/github.com/google/uuid",
"versionScheme": "semver",
},
Object {
"currentValue": "v2",
"def": "go_repository(
......
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