@@ -13,27 +13,65 @@ import {
1313import ComponentDetection from './componentDetection' ;
1414
1515async 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