Skip to content
This repository was archived by the owner on Jun 16, 2022. It is now read-only.

Go list implementation for detecting dependencies #5

Merged
merged 23 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
commit dist
  • Loading branch information
lseppala authored May 14, 2022
commit ad214b8f5f1825f47727fe6dba6e013d63a62cf6
42 changes: 0 additions & 42 deletions dist/go_mod_parser.js

This file was deleted.

9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ function detect() {
if (!fs_1.default.existsSync(goBuildTarget)) {
throw new Error(`The build target '${goBuildTarget}' does not exist`);
}
if (goModDir !== "." && !goBuildTarget.startsWith(goModDir)) {
if (goModDir !== '.' && !goBuildTarget.startsWith(goModDir)) {
throw new Error(`The build target ${goBuildTarget} is not a sub-directory of ${goModDir}`);
}
}
const metadataInput = core.getInput('metadata');
process.chdir(goModPath);
process.chdir(goModDir);
console.log(`Running go package detection in ${path} on build target ${goBuildTarget}`);
const options = { detector };
if (metadataInput) {
Expand Down Expand Up @@ -110,7 +110,10 @@ const path_1 = __importDefault(__nccwpck_require__(1017));
// format "${GO_PACKAGE}@v{VERSION}"
function parseDependents(contents) {
// split the input by newlines, sort, and dedup
const packages = Array.from(new Set(contents.split('\n').map(p => p.trim()).sort()));
const packages = Array.from(new Set(contents
.split('\n')
.map((p) => p.trim())
.sort()));
const entries = {};
packages.forEach((pkg) => {
if (!pkg)
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions dist/parse-go-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDependents = void 0;
const processor_1 = require("@github/dependency-submission-toolkit/dist/processor");
const path_1 = __importDefault(require("path"));
// processes a list of go dependencies, one dependency per line, matching the
// format "${GO_PACKAGE}@v{VERSION}"
function parseDependents(contents) {
// split the input by newlines, sort, and dedup
const packages = Array.from(new Set(contents
.split('\n')
.map((p) => p.trim())
.sort()));
const entries = {};
packages.forEach((pkg) => {
if (!pkg)
return;
const [qualifiedPackage, version] = pkg.split('@');
// URI-encode slashes in the namespace
const namespace = encodeURIComponent(path_1.default.dirname(qualifiedPackage));
const name = path_1.default.basename(qualifiedPackage);
const targetPkg = `pkg:golang/${namespace}/${name}@${version}`;
entries[targetPkg] = new processor_1.Entry(targetPkg);
});
return entries;
}
exports.parseDependents = parseDependents;