1
- const fetch = require ( 'node-fetch' ) ;
1
+ const fetch = require ( 'node-fetch' ) ; // Use CommonJS require for v2.x
2
2
const { setFailed, getInput, setOutput } = require ( '@actions/core' ) ;
3
3
4
4
async function run ( ) {
@@ -9,6 +9,7 @@ async function run() {
9
9
const imageName = getInput ( 'image_name' ) ;
10
10
const severity = getInput ( 'severity' ) ;
11
11
const publish = getInput ( 'publish' ) ;
12
+ const failOnSeverity = getInput ( 'fail_on_severity' ) ; // Get user-defined severity level
12
13
13
14
// Step 1: Trigger the scan and get the scan_id
14
15
const triggerResponse = await fetch ( `${ apiHost } /api/v0/scan?image=${ imageName } &severity=${ severity } &publish=${ publish } ` , {
@@ -67,12 +68,11 @@ async function run() {
67
68
// Step 3: Check the scan report for vulnerabilities
68
69
const reportResponse = await fetch ( reportUrl ) ;
69
70
const reportData = await reportResponse . json ( ) ;
70
- const failOnSeverity = getInput ( 'fail_on_severity' ) ; // Get user-defined severity level
71
- // const hasVulnsToFail = reportData.vulnerabilities.some(vuln => vuln.severity === failOnSeverity);
72
71
73
72
if ( failOnSeverity ) {
74
73
// Split the severities into an array
75
74
const severitiesToFailOn = failOnSeverity . split ( ',' ) . map ( sev => sev . trim ( ) . toUpperCase ( ) ) ;
75
+
76
76
// Check if the report contains any vulnerabilities matching the specified severities
77
77
const hasVulnsToFail = reportData . vulnerabilities . some ( vuln =>
78
78
severitiesToFailOn . includes ( vuln . severity )
@@ -86,8 +86,8 @@ async function run() {
86
86
console . log ( 'No fail_on_severity defined, proceeding without failing the job.' ) ;
87
87
}
88
88
} catch ( error ) {
89
- setFailed ( error . message ) ;
89
+ setFailed ( error . message ) ;
90
90
}
91
91
}
92
92
93
- run ( ) ;
93
+ run ( ) ;
0 commit comments