pipelineanalytics

package module
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 10 Imported by: 0

README

pipeline-analytics-sdk-go

CI Go Reference Codecov

A Go client for pipeline-analytics's REST API, generated from its OpenAPI spec with oapi-codegen. It saves you from hand-rolling HTTP requests, retries and pagination against the API yourself.

Requirements

  • Go 1.27 or later.
  • A running pipeline-analytics instance.
  • A session cookie for that instance (see "Authentication" below) — every endpoint except GetVersion and the two webhook receivers needs one.

Installation

go get github.com/alrayyes/pipeline-analytics-sdk-go@latest

Pin an exact tagged version (@v0.1.0) once one exists, rather than tracking @latest in anything but a quick trial.

Authentication

pipeline-analytics authenticates browsers with WebAuthn, not an API token — there's no headless credential-grant flow in its spec, so this SDK can't log in for you. Get a session cookie by logging into the dashboard in a browser, opening dev tools, and copying the session cookie's value. Pass it to New or set PIPELINE_ANALYTICS_SESSION in the environment:

client, err := pipelineanalytics.New("https://pipeline-analytics.example.com",
    pipelineanalytics.WithSessionCookie(os.Getenv("PIPELINE_ANALYTICS_SESSION")),
)

A session cookie expires the same way it would in a browser; there's nothing in this SDK to refresh it automatically.

Usage

GetVersion needs no session and is a good first call to prove the client reaches the server at all:

package main

import (
	"context"
	"fmt"
	"log"

	pipelineanalytics "github.com/alrayyes/pipeline-analytics-sdk-go"
)

func main() {
	client, err := pipelineanalytics.New("https://pipeline-analytics.example.com")
	if err != nil {
		log.Fatal(err)
	}

	resp, err := client.GetVersionWithResponse(context.Background())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("server version:", resp.JSON200.Version)
}

Listing tracked repos needs a session, and demonstrates the pagination iterator and error handling:

client, err := pipelineanalytics.New(
	"https://pipeline-analytics.example.com",
	pipelineanalytics.WithSessionCookie(os.Getenv("PIPELINE_ANALYTICS_SESSION")),
)
if err != nil {
	log.Fatal(err)
}

it := client.ListRepos(context.Background(), nil)
for repo := range it.All() {
	fmt.Println(repo.Identifier, repo.IngestionStatus)
}
if err := it.Err(); err != nil {
	var apiErr *pipelineanalytics.APIError
	if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusUnauthorized {
		log.Fatal("session cookie expired or invalid")
	}
	log.Fatal(err)
}

Every other operation follows the generated ClientWithResponses pattern — client.<Operation>WithResponse(ctx, ...) returns a typed response whose JSON200/JSON4xx fields hold the decoded body. Use DecodeError to turn a failed response into a *pipelineanalytics.APIError uniformly:

resp, err := client.GetRepoUsageWithResponse(ctx, repoID, nil)
if err != nil {
	return err // transport failure -- already retried
}
if apiErr := pipelineanalytics.DecodeError(resp.HTTPResponse.StatusCode, resp.Body, resp.HTTPResponse.Header); apiErr != nil {
	return apiErr
}

The client retries a 429 or 5xx response with exponential backoff and jitter (honoring a server-sent Retry-After), and never retries any other 4xx. Tune it with WithRetry, or swap the underlying *http.Client entirely with WithHTTPClient.

Reports

Each green push to main publishes its test and coverage reports at apis.ryankes.eu/pipeline-analytics-sdk-go/reports/: JUnit XML under tests/, and the HTML view, Cobertura XML and Go profile under coverage/.

Regenerating the client

See CONTRIBUTING.md — the generated code is pinned to a specific pipeline-analytics commit and shouldn't drift from it silently.

Contributing

See CONTRIBUTING.md for building, testing and the release process.

License

MIT — a permissive license for the client, independent of pipeline-analytics' own AGPL-3.0.

Documentation

Overview

Package pipelineanalytics is a client for the pipeline-analytics REST API (github.com/alrayyes/pipeline-analytics).

Every operation except GetVersion and the two webhook receivers requires an authenticated session. pipeline-analytics authenticates browsers with WebAuthn, not an API token -- there is no headless credential-grant flow in the spec. Obtain a session cookie by logging into the dashboard in a browser and copying the "session" cookie's value; pass it to New or set PIPELINE_ANALYTICS_SESSION. See the README for the full explanation and an example.

Index

Constants

View Source
const SessionCookieEnvVar = "PIPELINE_ANALYTICS_SESSION"

SessionCookieEnvVar is the environment variable New falls back to when no session cookie is passed explicitly via WithSessionCookie.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Code       string
	Message    string
	RequestID  string
}

APIError is returned by DecodeError for any pipeline-analytics response carrying an error body -- every 4xx/5xx in the spec shares the same {code, message} shape.

func DecodeError

func DecodeError(statusCode int, body []byte, headers http.Header) *APIError

DecodeError builds an *APIError from a generated response's status, body and headers, or returns nil when statusCode isn't an error. Every operation's generated response type carries these three fields under the same names (StatusCode via HTTPResponse, Body, and the headers on HTTPResponse), so this one helper covers all of them:

resp, err := client.ListReposWithResponse(ctx, nil)
if err != nil {
	return err // transport failure, already retried
}
if apiErr := pipelineanalytics.DecodeError(resp.HTTPResponse.StatusCode, resp.Body, resp.HTTPResponse.Header); apiErr != nil {
	return apiErr
}

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	*genclient.ClientWithResponses
}

Client is a pipeline-analytics API client. Construct one with New.

func New

func New(baseURL string, opts ...Option) (*Client, error)

New builds a Client against baseURL (the pipeline-analytics instance's origin, e.g. "https://pipeline-analytics.example.com").

func (*Client) ListRepos

func (c *Client) ListRepos(ctx context.Context, params *genclient.ListReposParams) *RepoIterator

ListRepos returns an iterator over every repo matching params, walking offset pages transparently. Range over it with a for-range loop; a non-nil error from Err (checked once the loop ends) means the walk stopped early on either a transport failure or an API error.

type Option

type Option func(*config)

Option configures a Client constructed by New.

func WithHTTPClient

func WithHTTPClient(hc genclient.HttpRequestDoer) Option

WithHTTPClient replaces the underlying HTTP client. The retry transport (WithRetry) wraps whatever Transport this client has set, so pass a client with a custom Transport already configured (proxies, mTLS, ...) rather than replacing RoundTrip yourself afterward.

func WithRetry

func WithRetry(maxRetries int, base time.Duration) Option

WithRetry overrides the default retry policy. maxRetries is the number of additional attempts after the first; base is the starting backoff before jitter and any server-sent Retry-After.

func WithSessionCookie

func WithSessionCookie(cookie string) Option

WithSessionCookie sets the session cookie sent on every request, overriding PIPELINE_ANALYTICS_SESSION.

type RepoIterator

type RepoIterator struct {
	// contains filtered or unexported fields
}

RepoIterator walks every page of a ListRepos call. Get Err after ranging to see whether the walk completed or stopped on an error.

func (*RepoIterator) All

func (it *RepoIterator) All() iter.Seq[genclient.Repo]

All returns a range-over-func iterator (Go 1.23+) yielding one Repo per call: `for repo := range it.All() { ... }`.

func (*RepoIterator) Err

func (it *RepoIterator) Err() error

Err returns the error that stopped iteration, or nil if it ran to completion (or hasn't started).

Directories

Path Synopsis
internal
genclient
Package genclient provides primitives to interact with the openapi HTTP API.
Package genclient provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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