1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-16 11:09:33 +02:00
sap-jenkins-library/pkg/sonar/report.go
Marc Bormeth b213af1089
Add Coverage Info to sonarscan.json (#3262)
* Add coverage metrics to report + influx

* Write unit tests

* Add integration test for Sonar Measures Component Service
2021-12-08 09:02:12 +01:00

40 lines
1.1 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"`
}
// 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)
}