From 9b7cea90596429d5b1243caecc15b1f79598cb85 Mon Sep 17 00:00:00 2001 From: Masayoshi Mizutani Date: Mon, 10 Jun 2024 16:51:25 +0900 Subject: [PATCH] Show secrets findings in comment (#108) --- pkg/usecase/comment_githug_pr_test.go | 13 +++++++++++++ pkg/usecase/templates/comment_body.md | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/usecase/comment_githug_pr_test.go b/pkg/usecase/comment_githug_pr_test.go index 7d66479..2b8891e 100644 --- a/pkg/usecase/comment_githug_pr_test.go +++ b/pkg/usecase/comment_githug_pr_test.go @@ -30,6 +30,19 @@ func TestRenderScanReport(t *testing.T) { {VulnerabilityID: "CVE-0000-0003", PkgName: "pkg4", Vulnerability: trivy.Vulnerability{Title: "Vuln title3", Severity: "CRITICAL"}}, }, }, + { + Target: "target3", + Secrets: []trivy.SecretFinding{ + { + RuleID: "slack-web-hook", + Category: "Slack", + Severity: "HIGH", + Title: "Slack Web Hook", + StartLine: 14, + EndLine: 15, + }, + }, + }, }, } added := trivy.Results{ diff --git a/pkg/usecase/templates/comment_body.md b/pkg/usecase/templates/comment_body.md index 8a88d69..23eeadb 100644 --- a/pkg/usecase/templates/comment_body.md +++ b/pkg/usecase/templates/comment_body.md @@ -57,11 +57,24 @@ {{ if ne .Metadata.TotalVulnCount 0 }} ## ⚠️ All detected vulnerabilities {{ range .Report.Results }} + +{{ if gt (len .Vulnerabilities) 0 }}
{{ .Target }}: ({{ .Vulnerabilities | len }}) {{ range .Vulnerabilities }}- {{ .VulnerabilityID }}: ( `{{ .PkgName }}` ) {{ .Title }} {{ end }}
+{{ end }} + +{{ if gt (len .Secrets) 0 }} +
+{{ .Target }}: ({{ .Secrets | len }}) + +{{ range .Secrets }}- `{{ .RuleID }}`: {{ .Title }} ({{ .StartLine }}L-{{ .EndLine }}L) +{{ end }} +
+{{ end }} + {{ end }} {{ end }}