gitlab

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitlab answers the cleanup engine's forge questions — does a project exist, which merge requests contain a commit, does one commit contain another — against the GitLab REST API, with credentials taken from the environment or glab's config file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Credentials

func Credentials(host string) (token, baseURL string, err error)

Credentials returns the token and API root ("<protocol>://<api host>/api/v4") for a GitLab host, which must be one of KnownHosts. GITLAB_TOKEN applies only to its own host — GITLAB_HOST's hostname, else gitlab.com — and wins there; every other token comes from glab's config file, which also supplies the API host and protocol. Where GITLAB_TOKEN is in use and the config names neither for the host, GITLAB_HOST's scheme and host[:port] do. The glab binary and the system keyring are never consulted, so a token glab keeps in the keyring is not found.

func KnownHosts

func KnownHosts() []string

KnownHosts returns the hosts glab's config file lists, GITLAB_HOST's hostname, and gitlab.com when GITLAB_TOKEN is set without GITLAB_HOST — lowercased, deduplicated and sorted. A config file that exists but cannot be read or parsed contributes no hosts and is reported as a warning.

Types

type Client

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

Client queries GitLab hosts. It is safe for concurrent use and keeps one API client per host and one project lookup per project for its lifetime.

func New

func New(opts Options) *Client

New returns a Client configured by opts.

func (*Client) Changes

func (c *Client) Changes(ctx context.Context, p forge.Project, sha string) ([]forge.Change, error)

Changes returns every merge request in p that contains the commit sha, whatever its state. A commit p does not hold yields an error wrapping forge.ErrCommitUnknown; a missing project, forge.ErrProjectNotFound.

func (*Client) ClosedChanges added in v0.2.0

func (c *Client) ClosedChanges(context.Context, []forge.Project, string) (map[forge.Project][]forge.Change, error)

ClosedChanges finds nothing and asks GitLab nothing: Changes already lists the merge requests closed without merging.

func (*Client) Contains

func (c *Client) Contains(ctx context.Context, p forge.Project, ancestor, descendant string) (bool, error)

Contains reports whether ancestor, a full commit SHA, is an ancestor of (or equal to) descendant, a SHA or ref, in p; commits sharing no history are not. Either side unknown to p yields an error wrapping forge.ErrCommitUnknown; a missing project, forge.ErrProjectNotFound.

func (*Client) DefaultBranch

func (c *Client) DefaultBranch(ctx context.Context, p forge.Project) (string, error)

DefaultBranch returns p's default branch.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, p forge.Project) error

Exists reports whether p is visible to the client's credentials; a missing or invisible project yields an error wrapping forge.ErrProjectNotFound.

type Options

type Options struct {
	// BaseURL, when set, is the API root every host is served from, and
	// Token is the token sent to it; Credentials, and with it the
	// KnownHosts check, is then never consulted.
	BaseURL string
	Token   string
	// HTTPClient carries every request; nil selects net/http's default
	// transport. Either way the Client follows no redirect that changes
	// scheme or host, and gives a client without a Timeout one of 60
	// seconds; HTTPClient itself is not modified.
	HTTPClient *http.Client
}

Options configures a Client. The zero value resolves each host's token and API root through Credentials.

Jump to

Keyboard shortcuts

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