mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
989c47db2c
* add test cases for sonar pkg
* add sonar pkg
* read task report and write reports JSON
* use alias
* rename type
* set read permission on created files
* archive reports
* handle empty report lists
* use filepath
* simplify report creation
* improve error message
* Revert "archive reports"
This reverts commit ba4b56fec1
.
* improve test cases
* Add descriptions
Co-Authored-By: Stephan Aßmus <stephan.assmus@sap.com>
* improve tests
Co-Authored-By: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package sonar
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"github.com/magiconair/properties"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// TaskReportData encapsulates information about an executed Sonar scan task.
|
|
// https://pkg.go.dev/github.com/magiconair/properties@v1.8.0?tab=doc#Properties.Decode
|
|
type TaskReportData struct {
|
|
ProjectKey string `properties:"projectKey"`
|
|
TaskID string `properties:"ceTaskId"`
|
|
DashboardURL string `properties:"dashboardUrl"`
|
|
TaskURL string `properties:"ceTaskUrl"`
|
|
ServerURL string `properties:"serverUrl"`
|
|
ServerVersion string `properties:"serverVersion"`
|
|
}
|
|
|
|
//ReadTaskReport expects a file ".scannerwork/report-task.txt" to exist in the provided workspace directory,
|
|
//and parses its contents into the returned TaskReportData struct.
|
|
func ReadTaskReport(workspace string) (result TaskReportData, err error) {
|
|
reportFile := filepath.Join(workspace, ".scannerwork", "report-task.txt")
|
|
// read file content
|
|
reportContent, err := properties.LoadFile(reportFile, properties.UTF8)
|
|
if err != nil {
|
|
return
|
|
}
|
|
// read content into struct
|
|
err = reportContent.Decode(&result)
|
|
if err != nil {
|
|
err = errors.Wrapf(err, "decode %s", reportFile)
|
|
}
|
|
return
|
|
}
|