1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-21 19:48:53 +02:00

feat(reporting) update markdown reports (#2819)

This commit is contained in:
Oliver Nocon 2021-05-11 08:01:02 +02:00 committed by GitHub
parent 98fac0a455
commit 4b666003c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -482,7 +482,8 @@ func checkPolicyViolations(config *ScanOptions, scan *ws.Scan, sys whitesource,
Overview: []reporting.OverviewRow{
{Description: "Total number of licensing vulnerabilities", Details: fmt.Sprint(policyViolationCount)},
},
ReportTime: utils.Now(),
SuccessfulScan: policyViolationCount == 0,
ReportTime: utils.Now(),
}
// JSON reports are used by step pipelineCreateSummary in order to e.g. prepare an issue creation in GitHub
@ -628,7 +629,8 @@ func createCustomVulnerabilityReport(config *ScanOptions, scan *ws.Scan, alerts
{Description: "Total number of vulnerabilities", Details: fmt.Sprint(len(alerts))},
{Description: "Total number of high/critical vulnerabilities with CVSS score >= 7.0", Details: fmt.Sprint(severe)},
},
ReportTime: utils.Now(),
SuccessfulScan: severe == 0,
ReportTime: utils.Now(),
}
detailTable := reporting.ScanDetailTable{

View File

@ -222,7 +222,7 @@ func (s *ScanReport) ToHTML() ([]byte, error) {
return buf.Bytes(), nil
}
const reportMdTemplate = `## {{.Title}}
const reportMdTemplate = `## {{if .SuccessfulScan}}:white_check_mark:{{else}}:x:{{end}} {{.Title}}
<table>
{{range $s := .Subheaders -}}

View File

@ -90,8 +90,9 @@ func TestToMarkdown(t *testing.T) {
{"overview 1", "1", Green},
{"overview 2", "2", Green},
},
FurtherInfo: "this is further information",
ReportTime: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
FurtherInfo: "this is further information",
SuccessfulScan: true,
ReportTime: time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC),
DetailTable: ScanDetailTable{
Headers: []string{"column 1", "column 2"},
Rows: []ScanRow{
@ -107,7 +108,7 @@ func TestToMarkdown(t *testing.T) {
res, err := report.ToMarkdown()
result := string(res)
assert.NoError(t, err)
assert.Contains(t, result, `## Report Test Title`)
assert.Contains(t, result, `## :white_check_mark: Report Test Title`)
assert.Contains(t, result, `<td><b>sub 1:</b></td><td>1</td>`)
assert.Contains(t, result, `<td><b>sub 2:</b></td><td>2</td>`)
assert.Contains(t, result, `<tr><td>overview 1:</td><td>1</td></tr>`)
@ -132,6 +133,7 @@ func TestToMarkdown(t *testing.T) {
res, err := report.ToMarkdown()
result := string(res)
assert.NoError(t, err)
assert.Contains(t, result, `## :x: Report Test Title`)
assert.NotContains(t, result, "<details><summary><i>Report Test Title details:</i></summary>")
})
}