Documentation
¶
Index ¶
- func APIURL(host string) string
- func GetAndCacheVersion(client *gitlab.Client, host string) string
- func PaginateToChannel[T any](ctx context.Context, fetchFunc FetchPageFunc[T], opts PaginateOptions) <-chan Result[T]
- func RefreshOAuthTokenIfNeeded(host, currentToken string) (string, error)
- func WebURL(host, path string) string
- type Client
- type FetchPageFunc
- type PaginateOptions
- type RateLimitTransport
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAndCacheVersion ¶ added in v0.2.0
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
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.
Types ¶
type Client ¶
Client wraps the GitLab API client.
func NewClient ¶
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
NewClientFromHosts creates a client using the first authenticated host found in hosts.json.
func NewClientWithToken ¶
NewClientWithToken creates a new GitLab API client with the given token.
func NewOAuthClient ¶ added in v0.0.2
NewOAuthClient creates a new GitLab API client using an OAuth token.
func (*Client) GetVersion ¶ added in v0.2.0
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).
type FetchPageFunc ¶ added in v0.2.0
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.