From b0ce45bfff1ee2f5e9fa1c867972bca89f0a8610 Mon Sep 17 00:00:00 2001 From: Seth Rait Date: Mon, 22 Jul 2024 07:32:18 -0700 Subject: [PATCH] Cleanup code --- lib/index.js | 58 ++++++++------------------------------------- lib/main.js | 4 +--- lib/msdo-helpers.js | 2 -- lib/post.js | 4 +--- lib/pre.js | 4 +--- 5 files changed, 13 insertions(+), 59 deletions(-) diff --git a/lib/index.js b/lib/index.js index f51199c..6ad3884 100644 --- a/lib/index.js +++ b/lib/index.js @@ -32,73 +32,39 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.run = void 0; +exports.runMainJob = exports.runPostJob = exports.runPreJob = void 0; const core = __importStar(require("@actions/core")); const msdo_1 = require("./msdo"); const msdo_helpers_1 = require("./msdo-helpers"); const container_mapping_1 = require("./container-mapping"); const common = __importStar(require("@microsoft/security-devops-actions-toolkit/msdo-common")); -function run(runnerString) { +function runPreJob() { return __awaiter(this, void 0, void 0, function* () { - let runner = runnerString; - let command = getCommandType(); - switch (runner) { - case msdo_helpers_1.RunnerType.Main: - yield _runMain(command); - break; - case msdo_helpers_1.RunnerType.Pre: - yield _runPreJob(command); - break; - case msdo_helpers_1.RunnerType.Post: - yield _runPostJob(command); - break; - default: - throw new Error(`Invalid source type for the task: ${runnerString}`); - } - }); -} -exports.run = run; -function _runPreJob(command) { - return __awaiter(this, void 0, void 0, function* () { - if (command != msdo_helpers_1.CommandType.All) { - return; - } if (_toolIsEnabled(msdo_helpers_1.Tools.ContainerMapping)) { yield _getExecutor(container_mapping_1.ContainerMapping).runPreJob(); } }); } -function _runPostJob(command) { +exports.runPreJob = runPreJob; +function runPostJob() { return __awaiter(this, void 0, void 0, function* () { - if (command != msdo_helpers_1.CommandType.All) { - return; - } if (_toolIsEnabled(msdo_helpers_1.Tools.ContainerMapping)) { yield _getExecutor(container_mapping_1.ContainerMapping).runPostJob(); } }); } -function _runMain(command) { +exports.runPostJob = runPostJob; +function runMainJob() { return __awaiter(this, void 0, void 0, function* () { - if (command == msdo_helpers_1.CommandType.PreJob) { - yield _runPreJob(command); - } - else if (command == msdo_helpers_1.CommandType.PostJob) { - yield _runPostJob(command); - } - else if (command == msdo_helpers_1.CommandType.All || command == msdo_helpers_1.CommandType.Run) { - if (_toolIsEnabledOnInput(msdo_helpers_1.Inputs.Tools, msdo_helpers_1.Tools.ContainerMapping, true)) { - console.log("Scanning is not enabled. Skipping..."); - } - else { - yield _getExecutor(msdo_1.MicrosoftSecurityDevOps).runMain(); - } + if (_toolIsEnabledOnInput(msdo_helpers_1.Inputs.Tools, msdo_helpers_1.Tools.ContainerMapping, true)) { + console.log("Scanning is not enabled. Skipping..."); } else { - throw new Error(`Invalid command type for the main task: ${command}`); + yield _getExecutor(msdo_1.MicrosoftSecurityDevOps).runMain(); } }); } +exports.runMainJob = runMainJob; function _toolIsEnabled(toolName) { let enabled = false; enabled = _toolIsEnabledOnInput(msdo_helpers_1.Inputs.Tools, toolName, false); @@ -125,7 +91,3 @@ function _toolIsEnabledOnInput(inputName, toolName, isOnlyTool = false) { function _getExecutor(runner) { return new runner(); } -function getCommandType() { - const commandTypeString = core.getInput(msdo_helpers_1.Inputs.Command) || msdo_helpers_1.CommandType.Run; - return commandTypeString; -} diff --git a/lib/main.js b/lib/main.js index b2b00d1..c7895e1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,11 +34,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); const index_1 = require("./index"); -const msdo_helpers_1 = require("./msdo-helpers"); -const runner = msdo_helpers_1.RunnerType.Main; function runMain() { return __awaiter(this, void 0, void 0, function* () { - yield (0, index_1.run)(runner); + yield (0, index_1.runMainJob)(); }); } runMain().catch(error => { diff --git a/lib/msdo-helpers.js b/lib/msdo-helpers.js index b647de1..11742d3 100644 --- a/lib/msdo-helpers.js +++ b/lib/msdo-helpers.js @@ -24,8 +24,6 @@ var RunnerType; var CommandType; (function (CommandType) { CommandType["All"] = "all"; - CommandType["PreJob"] = "pre-job"; - CommandType["PostJob"] = "post-job"; CommandType["Run"] = "run"; })(CommandType || (exports.CommandType = CommandType = {})); var Tools; diff --git a/lib/post.js b/lib/post.js index a0f4d7f..f284cbe 100644 --- a/lib/post.js +++ b/lib/post.js @@ -34,11 +34,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); const index_1 = require("./index"); -const msdo_helpers_1 = require("./msdo-helpers"); -const runner = msdo_helpers_1.RunnerType.Post; function runPost() { return __awaiter(this, void 0, void 0, function* () { - yield (0, index_1.run)(runner); + yield (0, index_1.runPostJob)(); }); } runPost().catch((error) => { diff --git a/lib/pre.js b/lib/pre.js index caa16d7..7ff3e60 100644 --- a/lib/pre.js +++ b/lib/pre.js @@ -34,11 +34,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); const index_1 = require("./index"); -const msdo_helpers_1 = require("./msdo-helpers"); -const runner = msdo_helpers_1.RunnerType.Pre; function runPre() { return __awaiter(this, void 0, void 0, function* () { - yield (0, index_1.run)(runner); + yield (0, index_1.runPreJob)(); }); } runPre().catch((error) => {