diff --git a/src/inputs.ts b/src/inputs.ts index 508bf42..e039962 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -8,3 +8,4 @@ export const SCAN_MODE = getInput('scan-mode').toUpperCase() export const FAIL_ON_ALL_POLICY_SEVERITIES = getBooleanInput('fail-on-all-policy-severities') export const OUTPUT_PATH_OVERRIDE = getInput('output-path-override') export const DETECT_TRUST_CERT = getInput('detect-trust-cert') +export const IGNORE_PR_COMMENT_WHEN_PASSED = getBooleanInput('ignore-pr-comment-when-passed') \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index b01f5d2..3f77598 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ import { commentOnPR } from './comment' import { POLICY_SEVERITY, SUCCESS } from './detect/exit-codes' import { TOOL_NAME, findOrDownloadDetect, runDetect } from './detect/detect-manager' import { isPullRequest } from './github/github-context' -import { BLACKDUCK_API_TOKEN, BLACKDUCK_URL, DETECT_TRUST_CERT, DETECT_VERSION, FAIL_ON_ALL_POLICY_SEVERITIES, OUTPUT_PATH_OVERRIDE, SCAN_MODE } from './inputs' +import { BLACKDUCK_API_TOKEN, BLACKDUCK_URL, DETECT_TRUST_CERT, DETECT_VERSION, FAIL_ON_ALL_POLICY_SEVERITIES, OUTPUT_PATH_OVERRIDE, SCAN_MODE, IGNORE_PR_COMMENT_WHEN_PASSED } from './inputs' import { createRapidScanReportString } from './detect/reporting' import { uploadArtifact } from './github/upload-artifacts' import { CHECK_NAME } from './application-constants' @@ -116,8 +116,9 @@ export async function runWithPolicyCheck(blackduckPolicyCheck: GitHubCheck): Pro const failureConditionsMet = detectExitCode === POLICY_SEVERITY || FAIL_ON_ALL_POLICY_SEVERITIES const rapidScanReport = await createRapidScanReportString(policyViolations, hasPolicyViolations && failureConditionsMet) - - if (isPullRequest()) { + const shouldCommentOnPr = hasPolicyViolations || (!hasPolicyViolations && !IGNORE_PR_COMMENT_WHEN_PASSED) + + if (isPullRequest() && shouldCommentOnPr) { info('This is a pull request, commenting...') commentOnPR(rapidScanReport) info('Successfully commented on PR.')