github.com/jaylevin/jenkins-library@v1.230.4/pkg/sonar/sonar.go (about)

     1  package sonar
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/magiconair/properties"
     7  	"github.com/pkg/errors"
     8  )
     9  
    10  // TaskReportData encapsulates information about an executed Sonar scan task.
    11  // https://pkg.go.dev/github.com/magiconair/properties@v1.8.0?tab=doc#Properties.Decode
    12  type TaskReportData struct {
    13  	ProjectKey    string `properties:"projectKey"`
    14  	TaskID        string `properties:"ceTaskId"`
    15  	DashboardURL  string `properties:"dashboardUrl"`
    16  	TaskURL       string `properties:"ceTaskUrl"`
    17  	ServerURL     string `properties:"serverUrl"`
    18  	ServerVersion string `properties:"serverVersion"`
    19  }
    20  
    21  //ReadTaskReport expects a file ".scannerwork/report-task.txt" to exist in the provided workspace directory,
    22  //and parses its contents into the returned TaskReportData struct.
    23  func ReadTaskReport(workspace string) (result TaskReportData, err error) {
    24  	reportFile := filepath.Join(workspace, ".scannerwork", "report-task.txt")
    25  	// read file content
    26  	reportContent, err := properties.LoadFile(reportFile, properties.UTF8)
    27  	if err != nil {
    28  		return
    29  	}
    30  	// read content into struct
    31  	err = reportContent.Decode(&result)
    32  	if err != nil {
    33  		err = errors.Wrapf(err, "decode %s", reportFile)
    34  	}
    35  	return
    36  }