gitlab

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package gitlab provides a wrapper around the GitLab REST API v4 client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client wraps the official GitLab API client with project-specific configuration. It includes connection resilience: when GitLab is unreachable at startup, the server enters degraded mode and automatically recovers when connectivity is restored.

func NewClient

func NewClient(cfg *config.Config) (*Client, error)

NewClient creates an authenticated GitLab client from the provided configuration. When cfg.SkipTLSVerify is true, TLS certificate verification is disabled (for self-signed certs). The client includes a resilience transport that enables automatic recovery when GitLab becomes available after being unreachable at startup.

func NewClientWithToken

func NewClientWithToken(baseURL, token string, skipTLSVerify bool) (*Client, error)

NewClientWithToken creates an authenticated GitLab client with explicit parameters. Unlike NewClient, it does not require a full config.Config and is designed for use in the server pool where each client has a unique token but shares the same base URL and TLS settings. The client includes a resilience transport that enables automatic recovery when GitLab becomes available after being unreachable.

func (*Client) CurrentUser

func (c *Client) CurrentUser(ctx context.Context) (*CurrentUserInfo, error)

CurrentUser returns the identity of the authenticated GitLab user. It calls the /user API endpoint and returns both the numeric ID and username.

func (*Client) CurrentUsername deprecated

func (c *Client) CurrentUsername(ctx context.Context) (string, error)

CurrentUsername returns the username of the authenticated GitLab user.

Deprecated: Use Client.CurrentUser which returns both ID and username.

func (*Client) EnableLazyInit

func (c *Client) EnableLazyInit()

EnableLazyInit enables lazy re-initialization on subsequent API calls. Called when startup Initialize() fails so that the server can recover automatically when GitLab becomes available again.

func (*Client) EnsureInitialized

func (c *Client) EnsureInitialized(ctx context.Context)

EnsureInitialized attempts lazy re-initialization if the client was not initialized at startup (e.g. GitLab was down). This allows automatic recovery when GitLab becomes available again. Thread-safe via initMu. Includes a 30-second cooldown between attempts to avoid hammering GitLab. Called automatically by [resilienceTransport] on every SDK request.

func (*Client) GL

func (c *Client) GL() *gl.Client

GL returns the underlying gitlab client for use in tool handlers.

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context) (string, error)

Initialize validates GitLab connectivity via a direct HTTP health check (bypassing the SDK transport chain to avoid recursion). On success it marks the client as initialized and returns the GitLab version string.

func (*Client) IsEnterprise

func (c *Client) IsEnterprise() bool

IsEnterprise reports whether the GitLab instance is Premium/Ultimate.

func (*Client) IsInitialized

func (c *Client) IsInitialized() bool

IsInitialized returns true if Initialize() completed successfully.

func (*Client) MarkInitialized

func (c *Client) MarkInitialized()

MarkInitialized sets the initialized flag without running the full Initialize flow. Intended for test setups where the client is preconfigured with a token or mock credentials.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) (string, error)

Ping validates connectivity and authentication by calling the GitLab version endpoint. Returns the GitLab version string on success. Callers should wrap ctx with context.WithTimeout to bound the network round-trip.

func (*Client) SetEnterprise

func (c *Client) SetEnterprise(v bool)

SetEnterprise marks the client as connected to a Premium/Ultimate instance.

type CurrentUserInfo

type CurrentUserInfo struct {
	UserID   int
	Username string
}

CurrentUserInfo holds the identity of the authenticated GitLab user.

Jump to

Keyboard shortcuts

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