gitlab

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package gitlab resolves versions from a GitLab project's tags or releases, enriching candidates with the commit SHA the REST API returns for free.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Login

func Login(ctx context.Context, host, clientID string, prompt func(forge.Code)) error

Login runs the GitLab device flow against host and stores the minted token under it; see forge.DeviceLogin.

Types

type Option

type Option func(*Provider)

Option configures a Provider.

func WithStore

func WithStore(s tokenStore) Option

WithStore sets the token store the credential chain reads the clover-minted token from, for tests.

func WithToken

func WithToken(tok string) Option

WithToken injects a host-bound PAT credential directly, for tests exercising the authenticated path (and the exfil guard) without reading the machine's environment.

func WithTransport

func WithTransport(rt http.RoundTripper) Option

WithTransport overrides the HTTP transport, for tests. It also pins credential resolution to the injected PAT and explicit store (see credential), so a test never reaches the network and its auth path stays deterministic.

type Provider

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

Provider resolves versions from a GitLab project's tags or releases. The host is a per-marker value (gitlab.com or a self-managed instance), so the REST client is host-agnostic - each request carries its own absolute URL and its own per-host token - while one shared, cached, rate-limited transport covers every marker in a run. The tags REST endpoint accepts order_by=version&sort=desc, so the listing is genuinely newest-first without the GraphQL detour GitHub needs.

func New

func New(opts ...Option) *Provider

New returns the GitLab provider, wiring the token store the credential chain reads from. A store that cannot be located (no config dir) is left nil, so the chain simply skips that rung. The default keychain store is wired only on the real transport: a test transport keeps auth explicit (via WithToken/WithStore), so the machine's stored token never leaks into a test's auth path.

func (*Provider) AuthHint

func (p *Provider) AuthHint() string

AuthHint returns how to authenticate when no credential is found.

func (*Provider) Authenticate

func (p *Provider) Authenticate(context.Context) error

Authenticate reports whether a credential is available from any source in the chain. It does not verify the token over the network - only that one is present - and never blocks on a prompt. Absence is reported as errAnonymous rather than a hard failure, since anonymous reads still work (just rate-limited).

func (*Provider) Branches added in v0.3.10

func (p *Provider) Branches(ctx context.Context, r provider.Resource) ([]provider.Branch, error)

Branches lists the project's branches with their tip commits, for matching an allowed-branch pattern and the tip-equality fast path. It always paginates to exhaustion - a release branch can sort well past the first page - following the X-Next-Page header, since a partial list could silently miss the allowed branch.

func (*Provider) Color added in v0.3.10

func (p *Provider) Color(dark bool) color.Color

Color is the provider's brand color. See provider.Provider.Color.

func (*Provider) Credentialed added in v0.3.10

func (p *Provider) Credentialed(r provider.Resource) bool

Credentialed reports whether a credential applies to the resource's host, satisfying provider.CredentialChecker. It gates the default verification tier.

func (*Provider) Dated added in v0.2.8

func (p *Provider) Dated()

Dated marks the listing as date-bearing: tags and releases carry a creation date. A lightweight tag with no creation date falls to the post-discovery date check.

func (*Provider) DefaultBranch added in v0.3.10

func (p *Provider) DefaultBranch(ctx context.Context, r provider.Resource) (string, error)

DefaultBranch returns the project's default branch, for tag-on-trunk verification when no explicit allowed-branch pattern is set.

func (*Provider) Describe

func (p *Provider) Describe(r provider.Resource) string

Describe returns a human-readable label for a resource.

func (*Provider) Discover

func (p *Provider) Discover(ctx context.Context, r provider.Resource) ([]model.Candidate, error)

Discover lists candidate versions for a resource from tags or releases.

func (*Provider) DownloadAsset added in v0.3.14

func (p *Provider) DownloadAsset(
	ctx context.Context,
	r provider.Resource,
	asset model.Asset,
) (io.ReadCloser, error)

DownloadAsset streams a release asset's content, satisfying provider.AssetDownloader. With a credential the asset is read through its api/v4 link, which authorizes a private project's download where the browser URL 401s; anonymously the browser URL is fetched directly. The bearer is attached only when the API URL shares the host's API origin - a release link may point at an arbitrary external host, which must not receive the token - and any redirect off that origin (a subdomain object store, a scheme downgrade) drops the header.

func (*Provider) Identify added in v0.3.10

func (p *Provider) Identify(r provider.Resource) (string, string)

Identify returns the repository path and its landing page.

func (*Provider) Keys

func (p *Provider) Keys() []provider.Key

Keys reports the directive keys GitLab accepts, in canonical order.

func (*Provider) Name

func (p *Provider) Name() string

Name identifies the provider.

func (*Provider) Reachable added in v0.3.10

func (p *Provider) Reachable(
	ctx context.Context,
	r provider.Resource,
	branch, commit string,
) (bool, error)

Reachable reports whether commit is an ancestor of (or equal to) branch's tip: the merge base of the two refs is the commit itself exactly when the branch contains it.

func (*Provider) RecencyOrdered

func (p *Provider) RecencyOrdered()

RecencyOrdered marks the listing as newest-first, so a shallow lookup always holds the latest version; --deep is hinted only when a constrained marker finds no candidate while more pages remained.

func (*Provider) Resource

func (p *Provider) Resource(d directive.Directive) (provider.Resource, error)

Resource validates a directive into a GitLab resource. The repository is the project's full path: at least namespace/project, with nested groups allowed (group/subgroup/project), unlike GitHub's strict owner/name.

func (*Provider) URL

URL builds the web page for a resolved candidate: the tag page for the candidate's ref. Every release has a tag, so the tag page serves both source=tags and source=releases. Empty when the ref is unknown.

Jump to

Keyboard shortcuts

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