@@ -13,27 +13,65 @@ import {
13
13
import ComponentDetection from './componentDetection' ;
14
14
15
15
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 , {
26
52
correlator : correlatorInput ,
27
- id : github . context . runId . toString ( )
53
+ id : github . context . runId . toString ( ) ,
28
54
} ) ;
29
55
30
56
core . debug ( `Manifests: ${ manifests ?. length } ` ) ;
31
57
32
- manifests ?. forEach ( manifest => {
58
+ manifests ?. forEach ( ( manifest ) => {
33
59
core . debug ( `Manifest: ${ JSON . stringify ( manifest ) } ` ) ;
34
60
snapshot . addManifest ( manifest ) ;
35
61
} ) ;
36
62
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
+
37
75
submitSnapshot ( snapshot ) ;
38
76
}
39
77
0 commit comments