api

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIURL

func APIURL(host string) string

APIURL returns the API base URL for a given host.

func GetAndCacheVersion added in v0.2.0

func GetAndCacheVersion(client *gitlab.Client, host string) string

GetAndCacheVersion fetches the GitLab version from the API and caches it in the hosts config. Returns the version string on success, or an empty string on error (best-effort).

func PaginateToChannel added in v0.2.0

func PaginateToChannel[T any](ctx context.Context, fetchFunc FetchPageFunc[T], opts PaginateOptions) <-chan Result[T]

PaginateToChannel fetches items progressively using the provided fetch function and sends them to a channel. It automatically handles pagination and prefetching to ensure smooth streaming of large result sets.

The function returns a read-only channel that will be closed when all items have been fetched or an error occurs. Errors are sent through the channel as Result items with a non-nil Error field.

Example usage:

opts := api.PaginateOptions{PerPage: 100, BufferSize: 50}
fetchFunc := func(page int) ([]*gitlab.MergeRequest, *gitlab.Response, error) {
    listOpts := &gitlab.ListProjectMergeRequestsOptions{
        ListOptions: gitlab.ListOptions{Page: page, PerPage: opts.PerPage},
    }
    return client.MergeRequests.ListProjectMergeRequests(projectID, listOpts)
}
results := api.PaginateToChannel(ctx, fetchFunc, opts)
for result := range results {
    if result.Error != nil {
        // handle error
    }
    // process result.Item
}

func RefreshOAuthTokenIfNeeded added in v0.0.14

func RefreshOAuthTokenIfNeeded(host, currentToken string) (string, error)

RefreshOAuthTokenIfNeeded checks if the OAuth token is expired (or about to expire) and refreshes it. Returns the refreshed token on success, or the original token on failure. If both the refresh fails and the current token is expired, returns an error advising re-authentication.

func WebURL

func WebURL(host, path string) string

WebURL returns the web URL for a given host and path.

Types

type Client

type Client struct {
	*gitlab.Client
	// contains filtered or unexported fields
}

Client wraps the GitLab API client.

func NewClient

func NewClient(host string) (*Client, error)

NewClient creates a new authenticated GitLab API client. It automatically selects the correct client type based on the stored auth method.

func NewClientFromHosts added in v0.0.9

func NewClientFromHosts() (*Client, error)

NewClientFromHosts creates a client using the first authenticated host found in hosts.json.

func NewClientWithToken

func NewClientWithToken(host, token string) (*Client, error)

NewClientWithToken creates a new GitLab API client with the given token.

func NewOAuthClient added in v0.0.2

func NewOAuthClient(host, token string) (*Client, error)

NewOAuthClient creates a new GitLab API client using an OAuth token.

func (*Client) GetVersion added in v0.2.0

func (c *Client) GetVersion() string

GetVersion returns the cached GitLab version for this client's host. Returns an empty string if the version is not cached or unknown (graceful degradation).

func (*Client) Host

func (c *Client) Host() string

Host returns the hostname of the GitLab instance.

type FetchPageFunc added in v0.2.0

type FetchPageFunc[T any] func(page int) ([]T, *gitlab.Response, error)

FetchPageFunc is a function that fetches a single page of items. It receives the page number and should return the items, response metadata, and any error.

type PaginateOptions added in v0.2.0

type PaginateOptions struct {
	PerPage    int // Items per page (default: 100)
	MaxPages   int // Maximum pages to fetch (0 = unlimited)
	BufferSize int // Channel buffer size for prefetching (default: 100)
}

PaginateOptions configures pagination behavior.

type RateLimitTransport added in v0.4.0

type RateLimitTransport struct {
	Base http.RoundTripper
}

RateLimitTransport wraps an http.RoundTripper with automatic retry on HTTP 429 responses.

func (*RateLimitTransport) RoundTrip added in v0.4.0

func (t *RateLimitTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes the request and retries on HTTP 429 with exponential backoff.

type Result added in v0.2.0

type Result[T any] struct {
	Item  T
	Error error
}

Result wraps an item with a potential error.

Jump to

Keyboard shortcuts

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