Skip to content

Commit

Permalink
feat: show issue counts on status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
error418 committed Jul 12, 2019
1 parent 882836a commit 06429e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LOGGER } from "./logger";
import { SwingletreeComponent } from "./component";
import { SonarQubePlugin } from "./sonar/sonar";
import { ZapPlugin } from "./zap/zap";
import { TwistlockPlugin } from "./twistlock/twistlock";

// initialize dangling event handlers
container.get<CommitStatusSender>(CommitStatusSender);
Expand All @@ -15,6 +16,7 @@ container.get<GhAppInstallationHandler>(GhAppInstallationHandler);
const registry = new SwingletreeComponent.Registry([
SwingletreeCore,
SonarQubePlugin,
TwistlockPlugin,
ZapPlugin
]);

Expand Down
13 changes: 12 additions & 1 deletion src/twistlock/status-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ class TwistlockStatusEmitter {
eventBus.register(TwistlockEvents.TwistlockReportReceived, this.reportReceivedHandler, this);
}

private getIssueCount(event: TwistlockReportReceivedEvent): number {
let count = 0;
if (event.report.results && event.report.results.length > 0) {
event.report.results.forEach((result) => {
count += result.complianceDistribution.total + result.vulnerabilityDistribution.total;
});
}

return count;
}

private getConclusion(event: TwistlockReportReceivedEvent): "action_required" | "success" {
let conclusion: "success" | "action_required" = "success";
if (event.report.results && event.report.results.length > 0) {
Expand Down Expand Up @@ -59,7 +70,7 @@ class TwistlockStatusEmitter {
};

checkRun.output = {
title: `Twistlock scan result`,
title: `${this.getIssueCount(event)} issues found`,
summary: this.templateEngine.template<TwistlockModel.Template>(
Templates.TWISTLOCK_SCAN,
templateData
Expand Down
7 changes: 6 additions & 1 deletion src/zap/zap-status-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ class ZapStatusEmitter {
counts: riskCounts
};

let totalIssueCount = 0;
riskCounts.forEach((count) => {
totalIssueCount += count;
});

checkRun.output = {
title: `OWASP Zap scan result`,
title: `${totalIssueCount} issues found`,
summary: this.templateEngine.template<Zap.ReportTemplate>(
Templates.ZAP_SCAN,
templateData
Expand Down

0 comments on commit 06429e3

Please sign in to comment.