sonar

package
v1.249.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const EndpointCeTask = "ce/task"

EndpointCeTask API endpoint for https://sonarcloud.io/web_api/api/ce/task

View Source
const EndpointIssuesSearch = "issues/search"

EndpointIssuesSearch API endpoint for https://sonarcloud.io/web_api/api/issues/search

View Source
const EndpointMeasuresComponent = "measures/component"

EndpointIssuesSearch API endpoint for https://sonarcloud.io/web_api/api/measures/component

Variables

This section is empty.

Functions

func WriteReport added in v1.130.0

func WriteReport(data ReportData, reportPath string, writeToFile func(f string, d []byte, p os.FileMode) error) error

WriteReport ...

Types

type ComponentService added in v1.184.0

type ComponentService struct {
	Organization string
	Project      string
	Branch       string
	PullRequest  string
	// contains filtered or unexported fields
}

ComponentService ...

func NewMeasuresComponentService added in v1.184.0

func NewMeasuresComponentService(host, token, project, organization, branch, pullRequest string, client Sender) *ComponentService

NewMeasuresComponentService returns a new instance of a service for the measures/component endpoint.

func (*ComponentService) Component added in v1.184.0

func (*ComponentService) GetCoverage added in v1.184.0

func (service *ComponentService) GetCoverage() (*SonarCoverage, error)

func (*ComponentService) GetLinesOfCode added in v1.194.0

func (service *ComponentService) GetLinesOfCode() (*SonarLinesOfCode, error)

type IssueService added in v1.127.0

type IssueService struct {
	Organization string
	Project      string
	Branch       string
	PullRequest  string
	// contains filtered or unexported fields
}

IssueService ...

func NewIssuesService added in v1.127.0

func NewIssuesService(host, token, project, organization, branch, pullRequest string, client Sender) *IssueService

NewIssuesService returns a new instance of a service for the issues API endpoint.

func (*IssueService) GetNumberOfBlockerIssues added in v1.127.0

func (service *IssueService) GetNumberOfBlockerIssues() (int, error)

GetNumberOfBlockerIssues returns the number of issue with BLOCKER severity.

func (*IssueService) GetNumberOfCriticalIssues added in v1.127.0

func (service *IssueService) GetNumberOfCriticalIssues() (int, error)

GetNumberOfCriticalIssues returns the number of issue with CRITICAL severity.

func (*IssueService) GetNumberOfInfoIssues added in v1.127.0

func (service *IssueService) GetNumberOfInfoIssues() (int, error)

GetNumberOfInfoIssues returns the number of issue with INFO severity.

func (*IssueService) GetNumberOfMajorIssues added in v1.127.0

func (service *IssueService) GetNumberOfMajorIssues() (int, error)

GetNumberOfMajorIssues returns the number of issue with MAJOR severity.

func (*IssueService) GetNumberOfMinorIssues added in v1.127.0

func (service *IssueService) GetNumberOfMinorIssues() (int, error)

GetNumberOfMinorIssues returns the number of issue with MINOR severity.

func (*IssueService) SearchIssues added in v1.127.0

func (service *IssueService) SearchIssues(options *IssuesSearchOption) (*sonargo.IssuesSearchObject, *http.Response, error)

SearchIssues ...

type Issues added in v1.130.0

type Issues struct {
	Blocker  int `json:"blocker"`
	Critical int `json:"critical"`
	Major    int `json:"major"`
	Minor    int `json:"minor"`
	Info     int `json:"info"`
}

Issues ...

type IssuesSearchOption added in v1.127.0

type IssuesSearchOption struct {
	Branch       string `url:"branch,omitempty"`       // Description:"Branch key"
	Organization string `url:"organization,omitempty"` // Description:"Organization key"
	PullRequest  string `url:"pullRequest,omitempty"`  // Description:"Pull request id"
	// copied from https://github.com/magicsong/sonargo/blob/103eda7abc20bd192a064b6eb94ba26329e339f1/sonar/issues_service.go#L311
	AdditionalFields   string `url:"additionalFields,omitempty"`   // Description:"Comma-separated list of the optional fields to be returned in response. Action plans are dropped in 5.5, it is not returned in the response.",ExampleValue:""
	Asc                string `url:"asc,omitempty"`                // Description:"Ascending sort",ExampleValue:""
	Assigned           string `url:"assigned,omitempty"`           // Description:"To retrieve assigned or unassigned issues",ExampleValue:""
	Assignees          string `url:"assignees,omitempty"`          // Description:"Comma-separated list of assignee logins. The value '__me__' can be used as a placeholder for user who performs the request",ExampleValue:"admin,usera,__me__"
	Authors            string `url:"authors,omitempty"`            // Description:"Comma-separated list of SCM accounts",ExampleValue:"torvalds@linux-foundation.org"
	ComponentKeys      string `url:"componentKeys,omitempty"`      // Description:"Comma-separated list of component keys. Retrieve issues associated to a specific list of components (and all its descendants). A component can be a portfolio, project, module, directory or file.",ExampleValue:"my_project"
	ComponentRootUuids string `url:"componentRootUuids,omitempty"` // Description:"If used, will have the same meaning as componentUuids AND onComponentOnly=false.",ExampleValue:""
	ComponentRoots     string `url:"componentRoots,omitempty"`     // Description:"If used, will have the same meaning as componentKeys AND onComponentOnly=false.",ExampleValue:""
	ComponentUuids     string `url:"componentUuids,omitempty"`     // Description:"To retrieve issues associated to a specific list of components their sub-components (comma-separated list of component IDs). This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter. A component can be a project, module, directory or file.",ExampleValue:"584a89f2-8037-4f7b-b82c-8b45d2d63fb2"
	Components         string `url:"components,omitempty"`         // Description:"If used, will have the same meaning as componentKeys AND onComponentOnly=true.",ExampleValue:""
	CreatedAfter       string `url:"createdAfter,omitempty"`       // Description:"To retrieve issues created after the given date (inclusive). <br>Either a date (server timezone) or datetime can be provided. <br>If this parameter is set, createdSince must not be set",ExampleValue:"2017-10-19 or 2017-10-19T13:00:00+0200"
	CreatedAt          string `url:"createdAt,omitempty"`          // Description:"Datetime to retrieve issues created during a specific analysis",ExampleValue:"2017-10-19T13:00:00+0200"
	CreatedBefore      string `url:"createdBefore,omitempty"`      // Description:"To retrieve issues created before the given date (inclusive). <br>Either a date (server timezone) or datetime can be provided.",ExampleValue:"2017-10-19 or 2017-10-19T13:00:00+0200"
	CreatedInLast      string `url:"createdInLast,omitempty"`      // Description:"To retrieve issues created during a time span before the current time (exclusive). Accepted units are 'y' for year, 'm' for month, 'w' for week and 'd' for day. If this parameter is set, createdAfter must not be set",ExampleValue:"1m2w (1 month 2 weeks)"
	Issues             string `url:"issues,omitempty"`             // Description:"Comma-separated list of issue keys",ExampleValue:"5bccd6e8-f525-43a2-8d76-fcb13dde79ef"
	Languages          string `url:"languages,omitempty"`          // Description:"Comma-separated list of languages. Available since 4.4",ExampleValue:"java,js"
	P                  string `url:"p,omitempty"`                  // Description:"1-based page number",ExampleValue:"42"
	Ps                 string `url:"ps,omitempty"`                 // Description:"Page size. Must be greater than 0 and less or equal than 500",ExampleValue:"20"
	Resolutions        string `url:"resolutions,omitempty"`        // Description:"Comma-separated list of resolutions",ExampleValue:"FIXED,REMOVED"
	Resolved           string `url:"resolved,omitempty"`           // Description:"To match resolved or unresolved issues",ExampleValue:""
	Rules              string `url:"rules,omitempty"`              // Description:"Comma-separated list of coding rule keys. Format is &lt;repository&gt;:&lt;rule&gt;",ExampleValue:"squid:AvoidCycles"
	S                  string `url:"s,omitempty"`                  // Description:"Sort field",ExampleValue:""
	Severities         string `url:"severities,omitempty"`         // Description:"Comma-separated list of severities",ExampleValue:"BLOCKER,CRITICAL"
	SinceLeakPeriod    string `url:"sinceLeakPeriod,omitempty"`    // Description:"To retrieve issues created since the leak period.<br>If this parameter is set to a truthy value, createdAfter must not be set and one component id or key must be provided.",ExampleValue:""
	Statuses           string `url:"statuses,omitempty"`           // Description:"Comma-separated list of statuses",ExampleValue:"OPEN,REOPENED"
	Tags               string `url:"tags,omitempty"`               // Description:"Comma-separated list of tags.",ExampleValue:"security,convention"
	Types              string `url:"types,omitempty"`              // Description:"Comma-separated list of types.",ExampleValue:"CODE_SMELL,BUG"
}

IssuesSearchOption is a copy from magicsong/sonargo plus the "internal" fields organization, branch and pullrequest.

type MeasuresComponentOption added in v1.194.0

type MeasuresComponentOption struct {
	Branch      string `url:"branch,omitempty"`      // Description:"Branch key"
	PullRequest string `url:"pullRequest,omitempty"` // Description:"Pull request id"
	// copied from https://github.com/magicsong/sonargo/blob/master/sonar/measures_service.go#L53
	AdditionalFields string `url:"additionalFields,omitempty"` // Description:"Comma-separated list of additional fields that can be returned in the response.",ExampleValue:"periods,metrics"
	Component        string `url:"component,omitempty"`        // Description:"Component key",ExampleValue:"my_project"
	ComponentId      string `url:"componentId,omitempty"`      // Description:"Component id",ExampleValue:"AU-Tpxb--iU5OvuD2FLy"
	MetricKeys       string `url:"metricKeys,omitempty"`       // Description:"Comma-separated list of metric keys",ExampleValue:"ncloc,complexity,violations"
}

MeasuresComponentOption is a copy from magicsong/sonargo plus the "internal" field branch.

type ReportData added in v1.130.0

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,omitempty"`
	LinesOfCode    *SonarLinesOfCode `json:"linesOfCode,omitempty"`
}

ReportData is representing the data of the step report JSON

type Requester added in v1.127.0

type Requester struct {
	Client   Sender
	Host     string
	Username string
	Password string
}

Requester ...

func NewAPIClient added in v1.127.0

func NewAPIClient(host, token string, client Sender) *Requester

NewAPIClient ...

type Sender added in v1.127.0

type Sender interface {
	Send(*http.Request) (*http.Response, error)
}

Sender provides an interface to the piper http client for uid/pwd and token authenticated requests

type SonarCoverage added in v1.184.0

type SonarCoverage struct {
	Coverage          float32 `json:"coverage"`
	LineCoverage      float32 `json:"lineCoverage"`
	LinesToCover      int     `json:"linesToCover"`
	UncoveredLines    int     `json:"uncoveredLines"`
	BranchCoverage    float32 `json:"branchCoverage"`
	BranchesToCover   int     `json:"branchesToCover"`
	UncoveredBranches int     `json:"uncoveredBranches"`
}

type SonarLanguageDistribution added in v1.194.0

type SonarLanguageDistribution struct {
	LanguageKey string `json:"languageKey,omitempty"` // Description:"key of the language as retrieved from sonarqube. All languages (key + name) are available as API https://<sonarqube-instance>/api/languages/list ",ExampleValue:"java,js,web,go"
	LinesOfCode int    `json:"linesOfCode"`
}

type SonarLinesOfCode added in v1.194.0

type SonarLinesOfCode struct {
	Total                int                         `json:"total"`
	LanguageDistribution []SonarLanguageDistribution `json:"languageDistribution,omitempty"`
}

type TaskReportData

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"`
}

TaskReportData encapsulates information about an executed Sonar scan task. https://pkg.go.dev/github.com/magiconair/properties@v1.8.0?tab=doc#Properties.Decode

func ReadTaskReport

func ReadTaskReport(workspace string) (result TaskReportData, err error)

ReadTaskReport expects a file ".scannerwork/report-task.txt" to exist in the provided workspace directory, and parses its contents into the returned TaskReportData struct.

type TaskService added in v1.127.0

type TaskService struct {
	TaskID       string
	PollInterval time.Duration
	// contains filtered or unexported fields
}

TaskService ...

func NewTaskService added in v1.127.0

func NewTaskService(host, token, task string, client Sender) *TaskService

NewTaskService returns a new instance of a service for the task API endpoint.

func (*TaskService) GetTask added in v1.127.0

func (service *TaskService) GetTask(options *sonargo.CeTaskOption) (*sonargo.CeTaskObject, *http.Response, error)

GetTask ...

func (*TaskService) HasFinished added in v1.127.0

func (service *TaskService) HasFinished() (bool, error)

HasFinished ...

func (*TaskService) WaitForTask added in v1.127.0

func (service *TaskService) WaitForTask() error

WaitForTask ..

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL