Skip to content

Commit c3d7d17

Browse files
fix: empty report table
1 parent b077805 commit c3d7d17

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

pkg/gatecheck/list.go

+44-6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ func ListGrypeReport(dst io.Writer, src io.Reader) (*tablewriter.Table, error) {
134134

135135
table := matrix.Table(dst, header)
136136

137+
if len(report.Matches) == 0 {
138+
footer := make([]string, len(header))
139+
footer[len(header)-1] = "No Grype Vulnerabilities"
140+
table.SetFooter(footer)
141+
table.SetBorder(false)
142+
}
143+
137144
return table, nil
138145
}
139146

@@ -182,6 +189,13 @@ func listGrypeWithEPSS(dst io.Writer, src io.Reader, epssData *epss.Data) (*tabl
182189

183190
table := matrix.Table(dst, header)
184191

192+
if len(report.Matches) == 0 {
193+
footer := make([]string, len(header))
194+
footer[len(header)-1] = "No Grype Vulnerabilities"
195+
table.SetFooter(footer)
196+
table.SetBorder(false)
197+
}
198+
185199
return table, nil
186200
}
187201

@@ -211,6 +225,13 @@ func ListCyclonedx(dst io.Writer, src io.Reader) (*tablewriter.Table, error) {
211225
header := []string{"Cyclonedx CVE ID", "Severity", "Package", "Link"}
212226
table := matrix.Table(dst, header)
213227

228+
if len(report.Vulnerabilities) == 0 {
229+
footer := make([]string, len(header))
230+
footer[len(header)-1] = "No Cyclonedx Vulnerabilities"
231+
table.SetFooter(footer)
232+
table.SetBorder(false)
233+
}
234+
214235
return table, nil
215236
}
216237

@@ -252,6 +273,13 @@ func listCyclonedxWithEPSS(dst io.Writer, src io.Reader, epssData *epss.Data) (*
252273
header := []string{"Cyclonedx CVE ID", "Severity", "EPSS Score", "EPSS Prctl", "affected Packages", "Link"}
253274
table := matrix.Table(dst, header)
254275

276+
if len(report.Vulnerabilities) == 0 {
277+
footer := make([]string, len(header))
278+
footer[len(header)-1] = "No Cyclonedx Vulnerabilities"
279+
table.SetFooter(footer)
280+
table.SetBorder(false)
281+
}
282+
255283
return table, nil
256284
}
257285

@@ -290,20 +318,27 @@ func ListSemgrep(dst io.Writer, src io.Reader) (*tablewriter.Table, error) {
290318
header := []string{"Semgrep Check ID", "Owasp IDs", "Severity", "Impact", "link"}
291319
table := matrix.Table(dst, header)
292320

321+
if len(report.Results) == 0 {
322+
footer := make([]string, len(header))
323+
footer[len(header)-1] = "No Semgrep Findings"
324+
table.SetFooter(footer)
325+
table.SetBorder(false)
326+
}
327+
293328
return table, nil
294329
}
295330

296331
func listGitleaks(dst io.Writer, src io.Reader) (*tablewriter.Table, error) {
297-
report := &artifacts.GitLeaksReportMin{}
298-
if err := json.NewDecoder(src).Decode(report); err != nil {
332+
report := artifacts.GitLeaksReportMin{}
333+
if err := json.NewDecoder(src).Decode(&report); err != nil {
299334
return nil, err
300335
}
301336

302337
table := tablewriter.NewWriter(dst)
303338

304-
table.SetHeader([]string{"Gitleaks Rule ID", "File", "Commit", "Start Line"})
305-
306-
for _, finding := range *report {
339+
header := []string{"Gitleaks Rule ID", "File", "Commit", "Start Line"}
340+
table.SetHeader(header)
341+
for _, finding := range report {
307342
row := []string{
308343
finding.RuleID,
309344
finding.FileShort(),
@@ -314,7 +349,10 @@ func listGitleaks(dst io.Writer, src io.Reader) (*tablewriter.Table, error) {
314349
}
315350

316351
if report.Count() == 0 {
317-
table.SetFooter([]string{"No Gitleaks Findings"})
352+
footer := make([]string, len(header))
353+
footer[len(header)-1] = "No Gitleaks Findings"
354+
table.SetFooter(footer)
355+
table.SetBorder(false)
318356
}
319357

320358
return table, nil

0 commit comments

Comments
 (0)