1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/sonar/report.go

41 lines
1.2 KiB
Go

package sonar
import (
"encoding/json"
"os"
"path/filepath"
)
const reportFileName = "sonarscan.json"
//ReportData is representing the data of the step report JSON
type ReportData struct {
ServerURL string `json:"serverUrl"`
ProjectKey string `json:"projectKey"`
TaskID string `json:"taskId"`
ChangeID string `json:"changeID,omitempty"`
BranchName string `json:"branchName,omitempty"`
Organization string `json:"organization,omitempty"`
NumberOfIssues Issues `json:"numberOfIssues"`
Coverage *SonarCoverage `json:"coverage,omitempty"`
LinesOfCode *SonarLinesOfCode `json:"linesOfCode,omitempty"`
}
// Issues ...
type Issues struct {
Blocker int `json:"blocker"`
Critical int `json:"critical"`
Major int `json:"major"`
Minor int `json:"minor"`
Info int `json:"info"`
}
// WriteReport ...
func WriteReport(data ReportData, reportPath string, writeToFile func(f string, d []byte, p os.FileMode) error) error {
jsonData, err := json.Marshal(data)
if err != nil {
return err
}
return writeToFile(filepath.Join(reportPath, reportFileName), jsonData, 0644)
}