Skip to content

Commit 42d6a6f

Browse files
Merge pull request #3 from shivam-rawat-akto/master
run-test changes for github comments and checks
2 parents 30dab7d + 26e28c5 commit 42d6a6f

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

action.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ description: 'Secure your APIs using Akto scan in your GitHub workflow'
33
author: 'Akto'
44

55
inputs:
6-
AKTO_DASHBOARD_URL:
6+
AKTO_DASHBOARD_URL:
77
required: true
88
description: 'URL of your Akto dashboard. Note that this should be whitelisted from your VPC for GitHub to access'
9-
AKTO_API_KEY:
9+
AKTO_API_KEY:
1010
required: true
1111
description: 'Akto API Key for CI/CD Integration'
12-
AKTO_TEST_ID:
12+
AKTO_TEST_ID:
1313
required: true
1414
description: 'Id of the test that you want to run'
1515
START_TIME_DELAY:
1616
required: false
17-
description: 'You can add a delay of N seconds before Akto starts testing your APIs. Please put the value more than the time it takes your API server to boot up and initialize'
17+
description: 'You can add a delay of N seconds before Akto starts testing your APIs. Please put the value more than the time it takes your API server to boot up and initialize'
1818
OVERRIDDEN_TEST_APP_URL:
1919
required: false
2020
description: 'Run tests on a different application host'
@@ -24,11 +24,14 @@ inputs:
2424
BLOCK_LEVEL:
2525
required: false
2626
description: 'If vulnerabilties equal to or higher are found, the PR is failed. Set as HIGH, MEDIUM, LOW, NONE'
27-
27+
GITHUB_COMMIT_ID:
28+
required: false
29+
description: 'Github commit head sha'
30+
2831
runs:
2932
using: 'node16'
3033
main: 'index.js'
31-
34+
3235
branding:
3336
icon: 'play'
3437
color: 'purple'

index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const OVERRIDDEN_TEST_APP_URL = core.getInput('OVERRIDDEN_TEST_APP_URL')
1010
const WAIT_TIME_FOR_RESULT = core.getInput('WAIT_TIME_FOR_RESULT')
1111
const BLOCK_LEVEL = core.getInput('BLOCK_LEVEL') || "HIGH"
1212
const GITHUB_STEP_SUMMARY = process.env.GITHUB_STEP_SUMMARY
13+
const GITHUB_COMMIT_ID = core.getInput('GITHUB_COMMIT_ID')
1314

1415
async function logGithubStepSummary(message) {
1516
await core.summary.addRaw(`${message}`).addEOL();
@@ -19,7 +20,7 @@ function toInt(a) {
1920
if (a === '') return 0;
2021

2122
let ret = parseInt(a);
22-
23+
2324
if (isNaN(ret)) return 0;
2425

2526
return ret;
@@ -50,7 +51,7 @@ function exitIfBlockLevelBreached(resultLevel, blockLevel) {
5051

5152
function parseBlockLevel(BLOCK_LEVEL) {
5253
if (BLOCK_LEVEL === '') return 10;
53-
54+
5455
if (BLOCK_LEVEL === 'HIGH') return 3;
5556
if (BLOCK_LEVEL === 'MEDIUM') return 2;
5657
if (BLOCK_LEVEL === 'LOW') return 1;
@@ -62,8 +63,8 @@ function parseBlockLevel(BLOCK_LEVEL) {
6263

6364
async function waitTillComplete(testDetails, maxWaitTime) {
6465
let testingRunResultSummaryHexId = testDetails.testingRunResultSummaryHexId
65-
if (!testingRunResultSummaryHexId) return;
66-
66+
if (!testingRunResultSummaryHexId) return;
67+
6768
const pollStartTime = Math.floor(Date.now() / 1000);
6869
while (true) {
6970
pollCurrentTime = Math.floor(Date.now() / 1000);
@@ -133,14 +134,19 @@ async function run() {
133134
"repository": process.env.GITHUB_REPOSITORY,
134135
"repository_url": process.env.GITHUB_SERVER_URL + "/" + process.env.GITHUB_REPOSITORY,
135136
"branch": process.env.GITHUB_REF_NAME,
136-
"commit_sha": process.env.GITHUB_SHA
137+
"commit_sha": process.env.GITHUB_SHA,
138+
"pull_request_id" : process.env.GITHUB_REF
137139
}
138140
}
139141

140142
if (OVERRIDDEN_TEST_APP_URL) {
141143
data["overriddenTestAppUrl"] = OVERRIDDEN_TEST_APP_URL
142144
}
143145

146+
if (GITHUB_COMMIT_ID) {
147+
data["metadata"]["commit_sha_head"] = GITHUB_COMMIT_ID
148+
}
149+
144150
const config = {
145151
method: 'post',
146152
url: AKTO_START_TEST_ENDPOINT,
@@ -156,11 +162,11 @@ async function run() {
156162
console.log("Akto CI/CD test started")
157163

158164
let waitTimeForResult = toInt(WAIT_TIME_FOR_RESULT)
159-
waitTillComplete(res.data, waitTimeForResult);
165+
waitTillComplete(res.data, waitTimeForResult);
160166

161167
} catch (error) {
162168
core.setFailed(error.message);
163169
}
164170
}
165171

166-
run();
172+
run();

0 commit comments

Comments
 (0)