From e05c957f3d6b85e78bb1f82b5db9c6a95d298326 Mon Sep 17 00:00:00 2001 From: Jonathan Serafini Date: Thu, 21 Nov 2024 09:33:26 -0500 Subject: [PATCH 1/2] add support for triggerId --- source/src/params.ts | 3 +++ source/tests/params.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/source/src/params.ts b/source/src/params.ts index b811bd1..b15deea 100644 --- a/source/src/params.ts +++ b/source/src/params.ts @@ -34,6 +34,7 @@ const BoostParamEnvMap: BoostParamEnvMap = { scanDiffTimeout: "BOOST_DIFF_SCAN_TIMEOUT", scanMainTimeout: "BOOST_MAIN_SCAN_TIMEOUT", tmpDir: "BOOST_TMP_DIR", + triggerId: "BOOST_TRIGGER_ID", workingDirectory: "BOOST_WORKING_DIRECTORY", } @@ -60,6 +61,7 @@ class BoostParamsVars { scanDiffTimeout: string | undefined = "" scanMainTimeout: string | undefined = "" tmpDir: string = "" + triggerId: string | undefined = "" workingDirectory: string | undefined = "" } @@ -120,6 +122,7 @@ export class BoostParams extends BoostParamsVars { this.scanTimeout = tl.getInput("scanTimeout") this.scanDiffTimeout = tl.getInput("scanDiffTimeout") this.scanMainTimeout = tl.getInput("scanMainTimeout") + this.triggerId = tl.getInput("triggerId") this.workingDirectory = tl.getInput("workingDirectory") } diff --git a/source/tests/params.ts b/source/tests/params.ts index 7453147..1e04b36 100644 --- a/source/tests/params.ts +++ b/source/tests/params.ts @@ -64,6 +64,7 @@ describe("BoostParams", () => { ["BOOST_DIFF_SCAN_TIMEOUT", "scanTimeout"], ["BOOST_DIFF_SCAN_TIMEOUT", "scanDiffTimeout"], ["BOOST_MAIN_SCAN_TIMEOUT", "scanMainTimeout"], + ["BOOST_TRIGGER_ID", "triggerId"], ["BOOST_WORKING_DIRECTORY", "workingDirectory"], ] From 26b50703e15b34e9de8a7e5afec502576955ac4e Mon Sep 17 00:00:00 2001 From: Jonathan Serafini Date: Thu, 21 Nov 2024 09:37:06 -0500 Subject: [PATCH 2/2] add trigger subcmd invocation --- source/src/scanner.ts | 7 ++++++- source/tests/scanner.ts | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/source/src/scanner.ts b/source/src/scanner.ts index bd6cb22..51cce6e 100644 --- a/source/src/scanner.ts +++ b/source/src/scanner.ts @@ -77,7 +77,12 @@ export async function executeCLI(params: BoostParams) { } const cliRunner = task.tool(params.exePath) - cliRunner.arg(["scan", "repo"]) + if (params.triggerId != undefined) { + cliRunner.arg(["scan", "trigger"]) + } else { + cliRunner.arg(["scan", "repo"]) + } + if (params.additionalArgs) { cliRunner.arg(params.additionalArgs.split(" ")) } diff --git a/source/tests/scanner.ts b/source/tests/scanner.ts index 755bef6..615ab96 100644 --- a/source/tests/scanner.ts +++ b/source/tests/scanner.ts @@ -4,8 +4,8 @@ import * as fs from "fs" import * as os from "os" import * as path from "path" -import * as scanner from "../src/scanner" import { BoostParams } from "../src/params" +import * as scanner from "../src/scanner" const INITIAL_ENV = process.env @@ -106,6 +106,28 @@ describe("executeCLI", () => { }) }) + test("executes with trigger command", async () => { + const params = new BoostParams(process.env, task) + params.exePath = path.join(params.tmpDir, "script") + params.triggerId = "trigger" + + fs.closeSync(fs.openSync(params.exePath, "w")) + + const mockTool = task.tool as jest.Mock + const mockArg = jest.fn() + const mockExec = jest.fn(async () => 0) + mockTool.mockReturnValue({ + arg: mockArg, + exec: mockExec, + }) + + await scanner.executeCLI(params) + expect(mockArg).toHaveBeenCalledWith(["scan", "trigger"]) + expect(mockExec).toHaveBeenCalledWith({ + env: params.asExecEnv(process.env), + }) + }) + test("executes with additional args", async () => { const params = new BoostParams(process.env, task) params.exePath = path.join(params.tmpDir, "script")