Skip to content

Commit c479d8c

Browse files
committed
Fix input and handle to scan statuses
1 parent 35c4a0d commit c479d8c

4 files changed

Lines changed: 35 additions & 20 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ When `WARN_ON_SEVERITY` is specified, the action will:
6161
- `LOW`: Block on all severity vulnerabilities (low, medium, high)
6262

6363
### `POLLING_TIMEOUT`
64-
When `POLLING_TIMEOUT` is specified, the action will stop polling the scan result after the specified time (milliseconds).
65-
Defaults to 300 000ms (5 minutes).
64+
When `POLLING_TIMEOUT` is specified, the action will stop polling the scan result after the specified time in seconds.
65+
Defaults to 300 seconds (5 minutes).
6666

6767

6868
### Example with Vulnerability Blocking
@@ -135,6 +135,6 @@ jobs:
135135
EXTERNAL_ID: "App_12230045"
136136
BLOCK_ON_SEVERITY: "HIGH" # Optional: Block build on high severity vulnerabilities
137137
WARN_ON_SEVERITY: "MEDIUM" # Optional: Warn on medium severity vulnerabilities
138-
POLLING_TIMEOUT: 300000 # Optional: Stop polling the scan result after the specified time
138+
POLLING_TIMEOUT: 300 # Optional: Stop polling the scan result after the specified time
139139

140140
```

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ inputs:
6767
POLLING_TIMEOUT:
6868
description: >
6969
Stop polling the scan result after the specified time in milliseconds, default is 5 minutes.
70+
required: false
7071
runs:
7172
using: 'node20'
7273
main: 'main.js'

main.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ function run() {
106106
const block_on_severity = core.getInput("BLOCK_ON_SEVERITY");
107107
const warn_on_severity = core.getInput("WARN_ON_SEVERITY");
108108
const polling_timeout = core.getInput("POLLING_TIMEOUT");
109+
var parsed_polling_timeout;
110+
if (polling_timeout) {
111+
parsed_polling_timeout = parseInt(polling_timeout, 10);
112+
if (isNaN(parsed_polling_timeout)) {
113+
throw new Error("POLLING_TIMEOUT must be a number");
114+
}
115+
if (parsed_polling_timeout < 0) {
116+
throw new Error("POLLING_TIMEOUT must be greater or equal to 0");
117+
}
118+
}
109119
// Validate severity levels
110120
if (block_on_severity &&
111121
!["HIGH", "MEDIUM", "LOW"].includes(block_on_severity.toUpperCase())) {
@@ -261,12 +271,8 @@ function run() {
261271
for (const scan of scan_info) {
262272
const { mobile_app_id, scan_id } = scan;
263273
var maxWaitTime = 300000; // 5 minutes
264-
if (polling_timeout) {
265-
maxWaitTime = parseInt(polling_timeout, 10);
266-
// Fallback to default value if the value is incorrect
267-
if (isNaN(maxWaitTime)) {
268-
maxWaitTime = 300000;
269-
}
274+
if (parsed_polling_timeout) {
275+
maxWaitTime = parsed_polling_timeout * 1000;
270276
}
271277
// Poll for scan completion with 23-second intervals
272278
const pollInterval = 23000; // 23 seconds
@@ -285,8 +291,9 @@ function run() {
285291
continue;
286292
}
287293
const status_data = yield status_response.json();
288-
if (status_data.static_scan &&
289-
status_data.static_scan.status === "FAILED") {
294+
const scan_status = status_data.status || status_data.static_scan.status;
295+
if (scan_status &&
296+
["FAILED", "SCAN_ATTEMPT_ERROR", "CANCELLED"].includes(scan_status)) {
290297
console.log(`Scan ${scan_id} failed, skipping vulnerability check`);
291298
break;
292299
}

main.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ async function run() {
126126
const block_on_severity = core.getInput("BLOCK_ON_SEVERITY");
127127
const warn_on_severity = core.getInput("WARN_ON_SEVERITY");
128128
const polling_timeout = core.getInput("POLLING_TIMEOUT");
129+
var parsed_polling_timeout;
130+
if (polling_timeout) {
131+
parsed_polling_timeout = parseInt(polling_timeout, 10);
132+
if (isNaN(parsed_polling_timeout)) {
133+
throw new Error("POLLING_TIMEOUT must be a number");
134+
}
135+
if (parsed_polling_timeout < 0) {
136+
throw new Error("POLLING_TIMEOUT must be greater or equal to 0");
137+
}
138+
}
139+
129140
// Validate severity levels
130141
if (
131142
block_on_severity &&
@@ -318,12 +329,8 @@ async function run() {
318329
const { mobile_app_id, scan_id } = scan;
319330

320331
var maxWaitTime = 300000; // 5 minutes
321-
if (polling_timeout) {
322-
maxWaitTime = parseInt(polling_timeout, 10);
323-
// Fallback to default value if the value is incorrect
324-
if (isNaN(maxWaitTime)) {
325-
maxWaitTime = 300000;
326-
}
332+
if (parsed_polling_timeout) {
333+
maxWaitTime = parsed_polling_timeout * 1000;
327334
}
328335

329336
// Poll for scan completion with 23-second intervals
@@ -356,10 +363,10 @@ async function run() {
356363
}
357364

358365
const status_data = await status_response.json();
359-
366+
const scan_status = status_data.status || status_data.static_scan.status;
360367
if (
361-
status_data.static_scan &&
362-
status_data.static_scan.status === "FAILED"
368+
scan_status &&
369+
["FAILED", "SCAN_ATTEMPT_ERROR", "CANCELLED"].includes(scan_status)
363370
) {
364371
console.log(`Scan ${scan_id} failed, skipping vulnerability check`);
365372
break;

0 commit comments

Comments
 (0)