2021-03-12 16:05:07 +02:00
|
|
|
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 {
|
2022-02-07 17:41:36 +02:00
|
|
|
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"`
|
2021-03-12 16:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|