Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Rait committed Jul 22, 2024
1 parent daf2549 commit b0ce45b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 59 deletions.
58 changes: 10 additions & 48 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
4 changes: 1 addition & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 0 additions & 2 deletions lib/msdo-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions lib/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 1 addition & 3 deletions lib/pre.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit b0ce45b

Please sign in to comment.