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

Commit 68bf076

Browse files
committed
Move go parser test + updated go mod parser from github/dependency_snapshot_action repo
> > Co-authored-by: Mitchell Rysavy <[email protected]>
1 parent c154de1 commit 68bf076

File tree

11 files changed

+7204
-1485
lines changed

11 files changed

+7204
-1485
lines changed

dist/go_mod_parser.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.parseDependents = void 0;
4+
const processor_1 = require("@github/dependency-snapshot-action/dist/processor");
5+
function parseDependents(contents) {
6+
const stdoutArr = contents.split('\n');
7+
const splitStdoutArr = stdoutArr.map(function (line) {
8+
return line.split(' ');
9+
});
10+
const entries = {};
11+
const repoName = splitStdoutArr[0][0];
12+
splitStdoutArr.forEach((line) => {
13+
if (line === undefined || line.length < 2)
14+
return; // skip empty lines
15+
let targetEntry;
16+
const targetPkg = `pkg:golang/${line[0]}`;
17+
let dependencyEntry;
18+
const dependencyPkg = `pkg:golang/${line[1]}`;
19+
const matchFound = line[0].match(repoName);
20+
if (matchFound && matchFound.index != null) {
21+
entries[dependencyPkg] = new processor_1.Entry(dependencyPkg, 'direct');
22+
return;
23+
}
24+
if (targetPkg in entries) {
25+
targetEntry = entries[targetPkg];
26+
}
27+
else {
28+
targetEntry = new processor_1.Entry(targetPkg, 'indirect');
29+
entries[targetPkg] = targetEntry;
30+
}
31+
if (dependencyPkg in entries) {
32+
dependencyEntry = entries[dependencyPkg];
33+
}
34+
else {
35+
dependencyEntry = new processor_1.Entry(dependencyPkg, 'indirect');
36+
entries[dependencyPkg] = dependencyEntry;
37+
}
38+
targetEntry.addDependency(dependencyEntry);
39+
});
40+
return entries;
41+
}
42+
exports.parseDependents = parseDependents;

dist/index.js

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,15 @@
11
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
22
/******/ var __webpack_modules__ = ({
33

4-
/***/ 212:
5-
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
4+
/***/ 2850:
5+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
66

77
"use strict";
88

9-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10-
if (k2 === undefined) k2 = k;
11-
var desc = Object.getOwnPropertyDescriptor(m, k);
12-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13-
desc = { enumerable: true, get: function() { return m[k]; } };
14-
}
15-
Object.defineProperty(o, k2, desc);
16-
}) : (function(o, m, k, k2) {
17-
if (k2 === undefined) k2 = k;
18-
o[k2] = m[k];
19-
}));
20-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21-
Object.defineProperty(o, "default", { enumerable: true, value: v });
22-
}) : function(o, v) {
23-
o["default"] = v;
24-
});
25-
var __importStar = (this && this.__importStar) || function (mod) {
26-
if (mod && mod.__esModule) return mod;
27-
var result = {};
28-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29-
__setModuleDefault(result, mod);
30-
return result;
31-
};
329
Object.defineProperty(exports, "__esModule", ({ value: true }));
33-
const core = __importStar(__nccwpck_require__(5127));
34-
const dependency_snapshot_action_1 = __nccwpck_require__(8049);
10+
exports.parseDependents = void 0;
3511
const processor_1 = __nccwpck_require__(9642);
36-
let parseDependents;
37-
// eslint-disable-next-line prefer-const
38-
parseDependents = function (contents) {
12+
function parseDependents(contents) {
3913
const stdoutArr = contents.split('\n');
4014
const splitStdoutArr = stdoutArr.map(function (line) {
4115
return line.split(' ');
@@ -71,7 +45,45 @@ parseDependents = function (contents) {
7145
targetEntry.addDependency(dependencyEntry);
7246
});
7347
return entries;
48+
}
49+
exports.parseDependents = parseDependents;
50+
51+
52+
/***/ }),
53+
54+
/***/ 212:
55+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
56+
57+
"use strict";
58+
59+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
60+
if (k2 === undefined) k2 = k;
61+
var desc = Object.getOwnPropertyDescriptor(m, k);
62+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
63+
desc = { enumerable: true, get: function() { return m[k]; } };
64+
}
65+
Object.defineProperty(o, k2, desc);
66+
}) : (function(o, m, k, k2) {
67+
if (k2 === undefined) k2 = k;
68+
o[k2] = m[k];
69+
}));
70+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
71+
Object.defineProperty(o, "default", { enumerable: true, value: v });
72+
}) : function(o, v) {
73+
o["default"] = v;
74+
});
75+
var __importStar = (this && this.__importStar) || function (mod) {
76+
if (mod && mod.__esModule) return mod;
77+
var result = {};
78+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
79+
__setModuleDefault(result, mod);
80+
return result;
7481
};
82+
Object.defineProperty(exports, "__esModule", ({ value: true }));
83+
const core = __importStar(__nccwpck_require__(5127));
84+
const dependency_snapshot_action_1 = __nccwpck_require__(8049);
85+
const go_mod_parser_1 = __nccwpck_require__(2850);
86+
const parseDependentsFunc = go_mod_parser_1.parseDependents;
7587
// Set the detector information provided from the action workflow input
7688
const detector = {
7789
name: core.getInput('detector-name'),
@@ -81,11 +93,11 @@ const detector = {
8193
// If provided, set the metadata provided from the action workflow input
8294
const metadataInput = core.getInput('metadata');
8395
if (metadataInput.length < 1) {
84-
(0, dependency_snapshot_action_1.run)(parseDependents, { command: 'go mod graph' }, { detector });
96+
(0, dependency_snapshot_action_1.run)(parseDependentsFunc, { command: 'go mod graph' }, { detector });
8597
}
8698
else {
8799
const metadata = JSON.parse(metadataInput);
88-
(0, dependency_snapshot_action_1.run)(parseDependents, { command: 'go mod graph' }, { metadata, detector });
100+
(0, dependency_snapshot_action_1.run)(parseDependentsFunc, { command: 'go mod graph' }, { metadata, detector });
89101
}
90102

91103

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const _exports: import("ts-jest/dist/types").InitialOptionsTsJest;
2+
export = _exports;

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

0 commit comments

Comments
 (0)