Documentation
¶
Index ¶
- func NewHTTPClient(disableTLSVerify bool) *http.Client
- type Client
- func (c *Client) GetBranchLatestCommit(ctx context.Context, project, branch string) (string, float64, error)
- func (c *Client) GetCommitCountBetweenRefs(ctx context.Context, project, from, to string) (int, error)
- func (c *Client) GetEnvironment(ctx context.Context, project string, environmentID int) (environment schemas.Environment, err error)
- func (c *Client) GetProject(ctx context.Context, name string) (*goGitlab.Project, error)
- func (c *Client) GetProjectBranches(ctx context.Context, p schemas.Project) (refs schemas.Refs, err error)
- func (c *Client) GetProjectEnvironments(ctx context.Context, p schemas.Project) (envs schemas.Environments, err error)
- func (c *Client) GetProjectMostRecentTagCommit(ctx context.Context, projectName, filterRegexp string) (string, float64, error)
- func (c *Client) GetProjectPipelines(ctx context.Context, projectName string, ...) ([]*goGitlab.PipelineInfo, *goGitlab.Response, error)
- func (c *Client) GetProjectRunners(ctx context.Context, p schemas.Project) (runners schemas.Runners, err error)
- func (c *Client) GetProjectTags(ctx context.Context, p schemas.Project) (refs schemas.Refs, err error)
- func (c *Client) GetRefPipeline(ctx context.Context, ref schemas.Ref, pipelineID int) (p schemas.Pipeline, err error)
- func (c *Client) GetRefPipelineTestReport(ctx context.Context, ref schemas.Ref) (schemas.TestReport, error)
- func (c *Client) GetRefPipelineVariablesAsConcatenatedString(ctx context.Context, ref schemas.Ref, pipeline schemas.Pipeline) (string, error)
- func (c *Client) GetRefsFromPipelines(ctx context.Context, p schemas.Project, refKind schemas.RefKind) (refs schemas.Refs, err error)
- func (c *Client) GetRunner(ctx context.Context, project string, runnerID int) (runner schemas.Runner, err error)
- func (c *Client) ListPipelineBridges(ctx context.Context, projectNameOrID string, pipelineID int) (bridges []*goGitlab.Bridge, err error)
- func (c *Client) ListPipelineChildJobs(ctx context.Context, projectNameOrID string, parentPipelineID int) (jobs []schemas.Job, err error)
- func (c *Client) ListPipelineJobs(ctx context.Context, projectNameOrID string, pipelineID int) (jobs []schemas.Job, err error)
- func (c *Client) ListProjects(ctx context.Context, w config.Wildcard) ([]schemas.Project, error)
- func (c *Client) ListRefMostRecentJobs(ctx context.Context, ref schemas.Ref) (jobs []schemas.Job, err error)
- func (c *Client) ListRefPipelineJobs(ctx context.Context, ref schemas.Ref) (jobs []schemas.Job, err error)
- func (c *Client) ReadinessCheck(ctx context.Context) healthcheck.Check
- func (c *Client) UpdateVersion(version GitLabVersion)
- func (c *Client) Version() GitLabVersion
- type ClientConfig
- type GitLabVersion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHTTPClient ¶
NewHTTPClient creates an HTTP client with optional TLS verification disabling. It clones the default transport to preserve proxy settings and other defaults, then modifies TLS configuration as requested.
Types ¶
type Client ¶
type Client struct {
*goGitlab.Client // Embedded GitLab API client
// Readiness contains configuration to check if the GitLab instance
// is responsive and healthy via an HTTP endpoint.
Readiness struct {
URL string // URL for readiness checks
HTTPClient *http.Client // HTTP client used to perform readiness requests
}
RateLimiter ratelimit.Limiter // RateLimiter controls the rate of API requests to avoid hitting GitLab rate limits.
RateCounter *ratecounter.RateCounter // RateCounter tracks the number of requests over time for monitoring or throttling.
RequestsCounter atomic.Uint64 // RequestsCounter is an atomic counter for total requests sent.
RequestsLimit int // RequestsLimit is the maximum allowed number of requests within a certain period.
RequestsRemaining int // RequestsRemaining tracks how many requests can still be sent before hitting the limit.
// contains filtered or unexported fields
}
Client is a wrapper around the official go-gitlab client, adding support for rate limiting, request counting, readiness checks, and GitLab version tracking with concurrency safety.
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
NewClient creates and returns a new Client instance configured with the provided ClientConfig. It initializes the underlying GitLab client, sets up the HTTP clients, readiness check, rate limiting, and request counting.
func (*Client) GetBranchLatestCommit ¶
func (c *Client) GetBranchLatestCommit(ctx context.Context, project, branch string) (string, float64, error)
GetBranchLatestCommit fetches the latest commit ID and its timestamp for a specific branch in a project. It returns the commit short ID, the commit date as a Unix timestamp (float64), or an error if any occurs.
func (*Client) GetCommitCountBetweenRefs ¶
func (c *Client) GetCommitCountBetweenRefs(ctx context.Context, project, from, to string) (int, error)
GetCommitCountBetweenRefs retrieves the number of commits between two references in a GitLab project.
func (*Client) GetEnvironment ¶
func (c *Client) GetEnvironment(ctx context.Context, project string, environmentID int) (environment schemas.Environment, err error)
GetEnvironment retrieves detailed information about a specific environment in a GitLab project, including its latest deployment data if available.
func (*Client) GetProject ¶
GetProject retrieves a single project by its name from GitLab.
func (*Client) GetProjectBranches ¶
func (c *Client) GetProjectBranches(ctx context.Context, p schemas.Project) (refs schemas.Refs, err error)
GetProjectBranches retrieves all branches for a given project that match the regular expression pattern specified in the project's Pull.Refs.Branches.Regexp field. It paginates through all available branches, applies the regex filter, and returns the matching branches as refs.
func (*Client) GetProjectEnvironments ¶
func (c *Client) GetProjectEnvironments(ctx context.Context, p schemas.Project) (envs schemas.Environments, err error)
GetProjectEnvironments fetches the environments of a given GitLab project. It filters environments based on a regular expression defined in the project configuration.
func (*Client) GetProjectMostRecentTagCommit ¶
func (c *Client) GetProjectMostRecentTagCommit(ctx context.Context, projectName, filterRegexp string) (string, float64, error)
GetProjectMostRecentTagCommit retrieves the most recent tag commit for a project that matches a specified regular expression.
func (*Client) GetProjectPipelines ¶
func (c *Client) GetProjectPipelines( ctx context.Context, projectName string, options *goGitlab.ListProjectPipelinesOptions, ) ( []*goGitlab.PipelineInfo, *goGitlab.Response, error, )
GetProjectPipelines lists pipelines for a given project, supporting pagination and filters
func (*Client) GetProjectRunners ¶ added in v0.1.6
func (*Client) GetProjectTags ¶
func (c *Client) GetProjectTags(ctx context.Context, p schemas.Project) (refs schemas.Refs, err error)
GetProjectTags retrieves tags for a given project that match a specified regular expression.
func (*Client) GetRefPipeline ¶
func (c *Client) GetRefPipeline(ctx context.Context, ref schemas.Ref, pipelineID int) (p schemas.Pipeline, err error)
GetRefPipeline retrieves a specific pipeline by ID for a given ref (branch, tag, or MR)
func (*Client) GetRefPipelineTestReport ¶
func (c *Client) GetRefPipelineTestReport(ctx context.Context, ref schemas.Ref) (schemas.TestReport, error)
GetRefPipelineTestReport retrieves and aggregates test reports for a given pipeline reference, including optionally its child pipelines if configured to do so.
func (*Client) GetRefPipelineVariablesAsConcatenatedString ¶
func (c *Client) GetRefPipelineVariablesAsConcatenatedString(ctx context.Context, ref schemas.Ref, pipeline schemas.Pipeline) (string, error)
GetRefPipelineVariablesAsConcatenatedString returns filtered pipeline variables as a concatenated string
func (*Client) GetRefsFromPipelines ¶
func (c *Client) GetRefsFromPipelines(ctx context.Context, p schemas.Project, refKind schemas.RefKind) (refs schemas.Refs, err error)
GetRefsFromPipelines retrieves references (branches, tags, or merge requests) based on GitLab pipelines. It filters them using the project's configuration, including optional regex, max age, and deletion status.
func (*Client) GetRunner ¶ added in v0.1.6
func (c *Client) GetRunner(ctx context.Context, project string, runnerID int) (runner schemas.Runner, err error)
GetRunner retrieves detailed information about a specific runner in a GitLab project, including its latest deployment data if available.
func (*Client) ListPipelineBridges ¶
func (c *Client) ListPipelineBridges(ctx context.Context, projectNameOrID string, pipelineID int) (bridges []*goGitlab.Bridge, err error)
ListPipelineBridges retrieves all bridge jobs (i.e., jobs that trigger downstream pipelines) associated with a given pipeline ID in a specified project. It paginates through results and respects API rate limits.
func (*Client) ListPipelineChildJobs ¶
func (c *Client) ListPipelineChildJobs(ctx context.Context, projectNameOrID string, parentPipelineID int) (jobs []schemas.Job, err error)
ListPipelineChildJobs retrieves all jobs from child pipelines triggered by a given parent pipeline. It traverses through bridge jobs recursively to explore all levels of downstream pipelines.
func (*Client) ListPipelineJobs ¶
func (c *Client) ListPipelineJobs(ctx context.Context, projectNameOrID string, pipelineID int) (jobs []schemas.Job, err error)
ListPipelineJobs retrieves all jobs associated with a given pipeline ID for a specified project. It handles pagination and rate limiting automatically.
func (*Client) ListProjects ¶
ListProjects lists projects based on a wildcard configuration.
func (*Client) ListRefMostRecentJobs ¶
func (c *Client) ListRefMostRecentJobs(ctx context.Context, ref schemas.Ref) (jobs []schemas.Job, err error)
ListRefMostRecentJobs fetches the most recent state of jobs already held in memory (ref.LatestJobs) for a given GitLab reference (typically a branch or merge request ref). It supports both page-based and keyset pagination depending on the GitLab version.
func (*Client) ListRefPipelineJobs ¶
func (c *Client) ListRefPipelineJobs(ctx context.Context, ref schemas.Ref) (jobs []schemas.Job, err error)
ListRefPipelineJobs retrieves the list of jobs for the latest pipeline associated with a given ref. If configured, it also includes jobs from child pipelines.
func (*Client) ReadinessCheck ¶
func (c *Client) ReadinessCheck(ctx context.Context) healthcheck.Check
ReadinessCheck returns a healthcheck.Check function that performs an HTTP GET request to the configured readiness URL to verify if the GitLab service is ready to accept requests.
func (*Client) UpdateVersion ¶
func (c *Client) UpdateVersion(version GitLabVersion)
UpdateVersion safely updates the GitLab version stored in the client. It locks the mutex for writing to prevent concurrent access issues.
func (*Client) Version ¶
func (c *Client) Version() GitLabVersion
Version safely returns the current GitLab version stored in the client. It uses a read lock to allow concurrent readers.
type ClientConfig ¶
type ClientConfig struct {
URL string // Base URL of the GitLab instance
Token string // API token for authentication
UserAgentVersion string // User agent string for client identification
DisableTLSVerify bool // Whether to skip TLS verification (e.g., for self-signed certs)
ReadinessURL string // URL used for readiness checks
RateLimiter ratelimit.Limiter // Optional custom rate limiter implementation
}
ClientConfig holds configuration options needed to instantiate a new Client.
type GitLabVersion ¶
type GitLabVersion struct {
Version string // The version string of GitLab
}
GitLabVersion represents a GitLab version with additional methods for version comparison.
func NewGitLabVersion ¶
func NewGitLabVersion(version string) GitLabVersion
NewGitLabVersion creates a new GitLabVersion instance. It ensures the version string is prefixed with "v".
func (GitLabVersion) PipelineJobsKeysetPaginationSupported ¶
func (v GitLabVersion) PipelineJobsKeysetPaginationSupported() bool
PipelineJobsKeysetPaginationSupported checks if the GitLab instance version supports pipeline jobs keyset pagination, which is available in version 15.9 or later.