Skip to content

Commit

Permalink
Enable upload support for Contrast Assess Findings XML (#17)
Browse files Browse the repository at this point in the history
* For now this supports uploads of Assess Findings XML files that are
available on disk
* Support for retrieving findings from the Contrast API will be
forthcoming
  • Loading branch information
drdavella committed May 20, 2024
1 parent 993fda7 commit 206567c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ description:
automatically fix issues found.

inputs:
pixee-api-url:
pixee-api-url:
description: The base URL of the Pixee API
default: https://api.pixee.ai
tool:
description: >
The supported code scanning tool that produced the results being uploaded.
Allowed values: 'sonar', 'codeql', 'semgrep', 'defectdojo'
Allowed values: 'sonar', 'codeql', 'semgrep', 'defectdojo', 'contrast'
required: true
file:
description: Path to the tool's results file to share with Pixeebot.
Expand Down
16 changes: 15 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export async function run() {
const tool = getTool();

switch(tool){
case "contrast":
const contrastFile = await fetchOrLocateContrastResultsFile();
await uploadInputFile(tool, contrastFile);
core.info(`Uploaded ${contrastFile} to Pixeebot for analysis`);
break;
case "defectdojo":
const file = await fetchOrLocateDefectDojoResultsFile();
await uploadInputFile(tool, file);
Expand All @@ -34,7 +39,7 @@ export async function run() {
default:
throw new Error("Action not implemented for tool: " + tool);
}

const { prNumber } = getGitHubContext();
if (prNumber) {
await triggerPrAnalysis(prNumber);
Expand All @@ -51,6 +56,15 @@ async function fetchOrLocateDefectDojoResultsFile() {
return fetchOrLocateResultsFile("defectdojo", results, fileName);
}

async function fetchOrLocateContrastResultsFile() {
let file = core.getInput("file");
if (file !== "") {
return file;
}

throw new Error("Contrast requires a file to be provided");
}

async function fetchOrLocateSonarResultsFile(resultType : SONAR_RESULT) {
let results = resultType == "issues" ? await fetchSonarCloudIssues() : await fetchSonarCloudHotspots();
let fileName = `sonar-${resultType}.json`;
Expand Down
6 changes: 3 additions & 3 deletions src/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as core from "@actions/core";
import { UserError } from "./errors";

export type Tool = "sonar" | "codeql" | "semgrep" | "appscan" | "defectdojo";
export type Tool = "sonar" | "codeql" | "semgrep" | "appscan" | "defectdojo" | "contrast";

export type TOOL_PATH = "sonar_issues" | "sonar_hotspots" | "codeql" | "semgrep" | "appscan" | "defectdojo";
export type TOOL_PATH = "sonar_issues" | "sonar_hotspots" | "codeql" | "semgrep" | "appscan" | "defectdojo" | "contrast";

/**
* Helper function to get the selected tool from the action's inputs.
Expand All @@ -26,4 +26,4 @@ function validateTool(tool: Tool) {
}
}

const VALID_TOOLS: Tool[] = ["sonar", "codeql", "semgrep", "appscan", "defectdojo"];
const VALID_TOOLS: Tool[] = ["sonar", "codeql", "semgrep", "appscan", "defectdojo", "contrast"];

0 comments on commit 206567c

Please sign in to comment.