Skip to content

Commit 04aaaf6

Browse files
authored
Merge pull request #118 from advanced-security/ljones140/add-snapshot-inputs
Add Snapshot inputs
2 parents e0dcc85 + 0f3b6ae commit 04aaaf6

File tree

4 files changed

+104
-23
lines changed

4 files changed

+104
-23
lines changed

action.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ inputs:
2727
correlator:
2828
description: 'An optional identifier to distinguish between multiple dependency snapshots of the same type.'
2929
required: false
30+
detector-name:
31+
description: 'The name of the detector. If provided, detector-version and detector-url must also be provided.'
32+
required: false
33+
detector-version:
34+
description: 'The version of the detector. If provided, detector-name and detector-url must also be provided.'
35+
required: false
36+
detector-url:
37+
description: 'The URL of the detector. If provided, detector-name and detector-version must also be provided.'
38+
required: false
39+
snapshot-sha:
40+
description: 'The SHA of the commit to associate with the snapshot. If provided, snapshot-ref must also be provided.'
41+
required: false
42+
snapshot-ref:
43+
description: 'The Git reference to associate with the snapshot. If provided, snapshot-sha must also be provided.'
44+
required: false
3045
runs:
3146
using: 'node20'
3247
main: 'dist/index.js'

dist/index.js

Lines changed: 38 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.

index.ts

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,65 @@ import {
1313
import ComponentDetection from './componentDetection';
1414

1515
async function run() {
16-
let manifests = await ComponentDetection.scanAndGetManifests(core.getInput('filePath'));
17-
const correlatorInput = core.getInput('correlator')?.trim() || github.context.job;
18-
19-
let snapshot = new Snapshot({
20-
name: "Component Detection",
21-
version: "0.0.1",
22-
url: "https://github.com/advanced-security/component-detection-dependency-submission-action",
23-
},
24-
github.context,
25-
{
16+
let manifests = await ComponentDetection.scanAndGetManifests(
17+
core.getInput("filePath")
18+
);
19+
const correlatorInput =
20+
core.getInput("correlator")?.trim() || github.context.job;
21+
22+
// Get detector configuration inputs
23+
const detectorName = core.getInput("detector-name")?.trim();
24+
const detectorVersion = core.getInput("detector-version")?.trim();
25+
const detectorUrl = core.getInput("detector-url")?.trim();
26+
27+
// Validate that if any detector config is provided, all must be provided
28+
const hasAnyDetectorInput = detectorName || detectorVersion || detectorUrl;
29+
const hasAllDetectorInputs = detectorName && detectorVersion && detectorUrl;
30+
31+
if (hasAnyDetectorInput && !hasAllDetectorInputs) {
32+
core.setFailed(
33+
"If any detector configuration is provided (detector-name, detector-version, detector-url), all three must be provided."
34+
);
35+
return;
36+
}
37+
38+
// Use provided detector config or defaults
39+
const detector = hasAllDetectorInputs
40+
? {
41+
name: detectorName,
42+
version: detectorVersion,
43+
url: detectorUrl,
44+
}
45+
: {
46+
name: "Component Detection",
47+
version: "0.0.1",
48+
url: "https://github.com/advanced-security/component-detection-dependency-submission-action",
49+
};
50+
51+
let snapshot = new Snapshot(detector, github.context, {
2652
correlator: correlatorInput,
27-
id: github.context.runId.toString()
53+
id: github.context.runId.toString(),
2854
});
2955

3056
core.debug(`Manifests: ${manifests?.length}`);
3157

32-
manifests?.forEach(manifest => {
58+
manifests?.forEach((manifest) => {
3359
core.debug(`Manifest: ${JSON.stringify(manifest)}`);
3460
snapshot.addManifest(manifest);
3561
});
3662

63+
// Override snapshot ref and sha if provided
64+
const snapshotSha = core.getInput("snapshot-sha")?.trim();
65+
const snapshotRef = core.getInput("snapshot-ref")?.trim();
66+
67+
if (snapshotSha) {
68+
snapshot.sha = snapshotSha;
69+
}
70+
71+
if (snapshotRef) {
72+
snapshot.ref = snapshotRef;
73+
}
74+
3775
submitSnapshot(snapshot);
3876
}
3977

0 commit comments

Comments
 (0)