mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
c30e93bc6a
* Added SARIF and GH issue creation
63 lines
2.1 KiB
Go
63 lines
2.1 KiB
Go
package reporting
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
piperGithub "github.com/SAP/jenkins-library/pkg/github"
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
)
|
|
|
|
type Uploader interface {
|
|
CreateIssue(ghCreateIssueOptions *piperGithub.CreateIssueOptions) error
|
|
}
|
|
|
|
// UploadSingleReportToGithub uploads a single report to GitHub
|
|
func UploadSingleReportToGithub(scanReport IssueDetail, token, APIURL, owner, repository string, assignees []string, uploader Uploader) error {
|
|
// JSON reports are used by step pipelineCreateSummary in order to e.g. prepare an issue creation in GitHub
|
|
// ignore JSON errors since structure is in our hands
|
|
markdownReport, _ := scanReport.ToMarkdown()
|
|
options := piperGithub.CreateIssueOptions{
|
|
Token: token,
|
|
APIURL: APIURL,
|
|
Owner: owner,
|
|
Repository: repository,
|
|
Title: scanReport.Title(),
|
|
Body: markdownReport,
|
|
Assignees: assignees,
|
|
UpdateExisting: true,
|
|
}
|
|
err := uploader.CreateIssue(&options)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to upload results for '%v' into GitHub issue: %w", scanReport.Title(), err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// UploadMultipleReportsToGithub uploads a number of reports to GitHub, one per IssueDetail to create transparency
|
|
func UploadMultipleReportsToGithub(scanReports *[]IssueDetail, token, APIURL, owner, repository string, assignees, trustedCerts []string, uploader Uploader) error {
|
|
for i := 0; i < len(*scanReports); i++ {
|
|
vuln := (*scanReports)[i]
|
|
title := vuln.Title()
|
|
markdownReport, _ := vuln.ToMarkdown()
|
|
options := piperGithub.CreateIssueOptions{
|
|
Token: token,
|
|
APIURL: APIURL,
|
|
Owner: owner,
|
|
Repository: repository,
|
|
Title: title,
|
|
Body: markdownReport,
|
|
Assignees: assignees,
|
|
UpdateExisting: true,
|
|
TrustedCerts: trustedCerts,
|
|
}
|
|
|
|
log.Entry().Debugf("Creating/updating GitHub issue(s) with title %v in org %v and repo %v", title, owner, repository)
|
|
err := uploader.CreateIssue(&options)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to upload results for '%v' into GitHub issue: %w", vuln.Title(), err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|