Categorygithub.com/reinoudk/go-sonarcloud
repository
0.3.4
Repository: https://github.com/reinoudk/go-sonarcloud.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

go-sonarcloud

An HTTP client to interact with the SonarCloud API from Go. It uses a service structure similar to that of go-github.

Most code in the sonarcloud folder is generated by the code in gen, using gen/webservices.json as source of truth for the API endpoints. This is one of the first iterations of generating the API. It only supports JSON return types and skips some endpoints that need special handling of the return values.

See https://pkg.go.dev/github.com/reinoudk/go-sonarcloud/sonarcloud for supported endpoints.

Installation

go get github.com/reinoudk/go-sonarcloud

Usage

Use sonarcloud.NewClient to create a new client. It needs a SonarCloud organization and token, and optionally accepts an existing *http.Client.

After creating the client, create a new request from one of the endpoint-specific packages in sonarcloud/, i.e. projects.SearchRequest from github.com/reinoudk/go-sonarcloud/sonarcloud/projects. If an endpoint supports paging, you need to supply paging.PagingParams as well, though in that case it might be easier to use the All variant of the function. The example below, for instance, uses client.Projects.SearchAll(req) instead of client.Projects.Search(req, paging).

The page size for automatic paging is currently set to 100, but might be configurable later.

func main() {
    org, ok := os.LookupEnv("SONARCLOUD_ORG")
    if !ok {
        log.Fatalf("missing SONARCLOUD_ORG environment variable")
    }

    token, ok := os.LookupEnv("SONARCLOUD_TOKEN")
    if !ok {
        log.Fatalf("mising SONARCLOUD_TOKEN environment variable")
    }

    client := sonarcloud.NewClient(org, token, nil)
    req := projects.SearchRequest{}

    res, err := client.Projects.SearchAll(req)
    if err != nil {
        log.Fatalf("could not search projects: %+v", err)
    }

    fmt.Printf("%+v\n", res)
}

Re-generating the API

Use make gen to re-generate the API from the gen/webservices.json file. This file is sourced from the webservices/list endpoint.