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/sonar.go
Christopher Fenner 989c47db2c
feat(sonar): extract sonar project link to report JSON (#1390)
* 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>
2020-04-21 15:45:52 +02:00

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
}