sonar

package
v1.527.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: Apache-2.0 Imports: 16 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 CheckResponse added in v1.526.0

func CheckResponse(r *http.Response) error

CheckResponse returns an ErrorResponse in case the response has an error status code

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 CeTaskObject added in v1.526.0

type CeTaskObject struct {
	Task *Task `json:"task,omitempty"`
}

CeTaskObject represents the response of the ce/task API endpoint

type CeTaskOption added in v1.526.0

type CeTaskOption struct {
	AdditionalFields string `url:"additionalFields,omitempty"` // Description:"Comma-separated list of the optional fields to be returned in response.",ExampleValue:""
	Id               string `url:"id,omitempty"`               // Description:"Id of task",ExampleValue:"AU-Tpxb--iU5OvuD2FLy"
}

CeTaskOption represents the query options of the ce/task API endpoint

type Comment added in v1.526.0

type Comment struct {
	CreatedAt string `json:"createdAt,omitempty"`
	HTMLText  string `json:"htmlText,omitempty"`
	Key       string `json:"key,omitempty"`
	Login     string `json:"login,omitempty"`
	Markdown  string `json:"markdown,omitempty"`
	Updatable bool   `json:"updatable,omitempty"`
}

Comment represents a comment on an issue

type Component added in v1.526.0

type Component struct {
	AnalysisDate     string          `json:"analysisDate,omitempty"`
	Description      string          `json:"description,omitempty"`
	Enabled          bool            `json:"enabled,omitempty"`
	ID               string          `json:"id,omitempty"`
	Key              string          `json:"key,omitempty"`
	Language         string          `json:"language,omitempty"`
	LastAnalysisDate string          `json:"lastAnalysisDate,omitempty"`
	LeakPeriodDate   string          `json:"leakPeriodDate,omitempty"`
	LongName         string          `json:"longName,omitempty"`
	Measures         []*SonarMeasure `json:"measures,omitempty"`
	Name             string          `json:"name,omitempty"`
	Organization     string          `json:"organization,omitempty"`
	Path             string          `json:"path,omitempty"`
	Project          string          `json:"project,omitempty"`
	Qualifier        string          `json:"qualifier,omitempty"`
	Tags             []string        `json:"tags,omitempty"`
	UUID             string          `json:"uuid,omitempty"`
	Version          string          `json:"version,omitempty"`
	Visibility       string          `json:"visibility,omitempty"`
}

Component represents a SonarQube component with its measures

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 ErrorResponse added in v1.526.0

type ErrorResponse struct {
	Body     []byte
	Response *http.Response
	Message  string
}

ErrorResponse is returned by CheckResponse for API responses with an error status code

func (*ErrorResponse) Error added in v1.526.0

func (e *ErrorResponse) Error() string

Error implements the error interface

type History added in v1.526.0

type History struct {
	Date  string `json:"date,omitempty"`
	Value string `json:"value,omitempty"`
}

History represents a historical measure value

type Issue added in v1.526.0

type Issue struct {
	Actions      []string   `json:"actions,omitempty"`
	Assignee     string     `json:"assignee,omitempty"`
	Author       string     `json:"author,omitempty"`
	Comments     []*Comment `json:"comments,omitempty"`
	Component    string     `json:"component,omitempty"`
	CreationDate string     `json:"creationDate,omitempty"`
	Debt         string     `json:"debt,omitempty"`
	Effort       string     `json:"effort,omitempty"`
	Flows        []any      `json:"flows,omitempty"`
	Hash         string     `json:"hash,omitempty"`
	Key          string     `json:"key,omitempty"`
	Line         int        `json:"line,omitempty"`
	Message      string     `json:"message,omitempty"`
	Organization string     `json:"organization,omitempty"`
	Project      string     `json:"project,omitempty"`
	Rule         string     `json:"rule,omitempty"`
	Severity     string     `json:"severity,omitempty"`
	Status       string     `json:"status,omitempty"`
	Tags         []string   `json:"tags,omitempty"`
	TextRange    *TextRange `json:"textRange,omitempty"`
	Transitions  []string   `json:"transitions,omitempty"`
	Type         string     `json:"type,omitempty"`
	UpdateDate   string     `json:"updateDate,omitempty"`
	FromHotspot  bool       `json:"fromHotspot,omitempty"`
	Resolution   string     `json:"resolution,omitempty"`
	CloseDate    string     `json:"closeDate,omitempty"`
}

Issue represents a SonarQube issue

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(categories *[]Severity) (int, error)

GetNumberOfBlockerIssues returns the number of issue with BLOCKER severity.

func (*IssueService) GetNumberOfCriticalIssues added in v1.127.0

func (service *IssueService) GetNumberOfCriticalIssues(categories *[]Severity) (int, error)

GetNumberOfCriticalIssues returns the number of issue with CRITICAL severity.

func (*IssueService) GetNumberOfInfoIssues added in v1.127.0

func (service *IssueService) GetNumberOfInfoIssues(categories *[]Severity) (int, error)

GetNumberOfInfoIssues returns the number of issue with INFO severity.

func (*IssueService) GetNumberOfMajorIssues added in v1.127.0

func (service *IssueService) GetNumberOfMajorIssues(categories *[]Severity) (int, error)

GetNumberOfMajorIssues returns the number of issue with MAJOR severity.

func (*IssueService) GetNumberOfMinorIssues added in v1.127.0

func (service *IssueService) GetNumberOfMinorIssues(categories *[]Severity) (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) (*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 IssuesSearchObject added in v1.526.0

type IssuesSearchObject struct {
	Components  []*Component `json:"components,omitempty"`
	EffortTotal int          `json:"effortTotal,omitempty"`
	DebtTotal   int          `json:"debtTotal,omitempty"`
	Issues      []*Issue     `json:"issues,omitempty"`
	P           int          `json:"p,omitempty"`
	Ps          int          `json:"ps,omitempty"`
	Paging      *Paging      `json:"paging,omitempty"`
	Total       int          `json:"total,omitempty"`
	Facets      []string     `json:"facets,omitempty"`
}

IssuesSearchObject represents the response of the issues/search API endpoint

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 MeasuresComponentObject added in v1.526.0

type MeasuresComponentObject struct {
	Component *Component `json:"component,omitempty"`
	Periods   []*Period  `json:"periods,omitempty"`
}

MeasuresComponentObject represents the response of the measures/component API endpoint

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 Paging added in v1.526.0

type Paging struct {
	PageIndex int `json:"pageIndex,omitempty"`
	PageSize  int `json:"pageSize,omitempty"`
	Total     int `json:"total,omitempty"`
}

Paging is used in many API responses

type Period added in v1.526.0

type Period struct {
	Date      string `json:"date,omitempty"`
	Index     int64  `json:"index,omitempty"`
	Mode      string `json:"mode,omitempty"`
	Parameter string `json:"parameter,omitempty"`
	Value     string `json:"value,omitempty"`
	BestValue bool   `json:"bestValue,omitempty"`
}

Period represents a new code period

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"`
	Errors         []Severity        `json:"errors"`
	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 Severity added in v1.451.0

type Severity struct {
	SeverityType string `json:"severity"`
	IssueType    string `json:"error_type,omitempty"`
	IssueCount   int    `json:"issues,omitempty"`
}

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 SonarMeasure added in v1.526.0

type SonarMeasure struct {
	Metric    string     `json:"metric,omitempty"`
	Periods   []*Period  `json:"periods,omitempty"`
	Value     string     `json:"value,omitempty"`
	Histories []*History `json:"history,omitempty"`
	BestValue bool       `json:"bestValue,omitempty"`
}

SonarMeasure represents a single measure of a component

type Task added in v1.526.0

type Task struct {
	AnalysisID         string   `json:"analysisId,omitempty"`
	ComponentID        string   `json:"componentId,omitempty"`
	ComponentKey       string   `json:"componentKey,omitempty"`
	ComponentName      string   `json:"componentName,omitempty"`
	ComponentQualifier string   `json:"componentQualifier,omitempty"`
	ErrorMessage       string   `json:"errorMessage,omitempty"`
	ErrorStacktrace    string   `json:"errorStacktrace,omitempty"`
	ErrorType          string   `json:"errorType,omitempty"`
	ExecutedAt         string   `json:"executedAt,omitempty"`
	ExecutionTimeMs    int64    `json:"executionTimeMs,omitempty"`
	FinishedAt         string   `json:"finishedAt,omitempty"`
	HasErrorStacktrace bool     `json:"hasErrorStacktrace,omitempty"`
	HasScannerContext  bool     `json:"hasScannerContext,omitempty"`
	ID                 string   `json:"id,omitempty"`
	Logs               bool     `json:"logs,omitempty"`
	Organization       string   `json:"organization,omitempty"`
	ScannerContext     string   `json:"scannerContext,omitempty"`
	StartedAt          string   `json:"startedAt,omitempty"`
	Status             string   `json:"status,omitempty"`
	SubmittedAt        string   `json:"submittedAt,omitempty"`
	SubmitterLogin     string   `json:"submitterLogin,omitempty"`
	TaskType           string   `json:"taskType,omitempty"`
	Type               string   `json:"type,omitempty"`
	WarningCount       int      `json:"warningCount,omitempty"`
	Warnings           []string `json:"warnings,omitempty"`
}

Task represents a compute engine task

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 *CeTaskOption) (*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 ..

type TextRange added in v1.526.0

type TextRange struct {
	EndLine     int `json:"endLine,omitempty"`
	EndOffset   int `json:"endOffset,omitempty"`
	StartLine   int `json:"startLine,omitempty"`
	StartOffset int `json:"startOffset,omitempty"`
}

TextRange represents the location of an issue in a file

Jump to

Keyboard shortcuts

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