gitlabrelease

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 12 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 gitlabrelease is the "gitlab-release" Source: it lists the releases of a project on gitlab.com or on a self-managed GitLab instance.

Target coordinates: {"project": "group/subgroup/name"} (a full path with any number of subgroups) or {"project": "12345"} (the numeric project id). Include and exclude patterns, prerelease mode and the rest of the filtering belong to policy, not to this source.

Requests

List calls GET {base}/api/v4/projects/{project}/releases?order_by=created_at&sort=desc&per_page=100, where {project} is the URL-encoded path ("group%2Fsub%2Fname"), following pages until X-Next-Page is empty (a short page when the header is absent). At most 10 pages (1000 releases) are read: a project with more releases is truncated at that cap, newest first by created_at, and the older ones are never reported. The base URL is the root of the instance, "https://gitlab.com" by default, "https://HOST" for a self-managed instance, or "https://HOST/prefix" when GitLab is served under a relative URL root; a trailing "/api/v4" (any case) is accepted and ignored. A base URL with a query or a fragment is rejected.

Pages are ordered by created_at, not released_at, because released_at is settable by the releaser (a "historical" release may be backdated): a backdated release has a recent created_at and so is found on the first page.

The ETag of the first page, when GitLab sends one, is kept in FetchState.ETag and sent as If-None-Match. When it changed, List walks the pages only until one that holds a released entry at or below the newest created_at already seen (the "max_created_at" of the cursor): a new release costs one page, not the whole history. Releases that change without a new created_at are not seen by such a scan, so List ignores the validators and walks every page when the last such scan is 24 hours old or missing, and when an upcoming release is due (see below).

Each page is capped by the netguard client at 10 MiB unless the GitLab host has its own netguard.HostLimit.MaxBodyBytes; a project whose page of 100 releases is larger fails with an error (gitlab-org/gitlab-runner is about 1.3 MB per page).

Mapping

Raw is the tag name. PublishedAt is released_at (created_at when GitLab returns none). released_at is user-settable (a historical release is backdated, an upcoming one is dated in the future), so it is not proof of when the release appeared: the policy engine treats gitlab-release dates as untrusted and counts a cooldown from detection. The real creation time is kept in Metadata "created_at" (RFC 3339, UTC). Prerelease is nil: GitLab has no prerelease flag, so policy decides. URL and NotesURL are the release page ("_links.self" when it is an http(s) URL, otherwise built from the base URL and the project path). Metadata carries "created_at", "name" and the tagged commit "sha" when present.

Upcoming releases

A release whose released_at is in the future has upcoming_release set. It is not reported until it is released: List skips it and records the earliest such released_at in the cursor, and the first List call after that time ignores the validators (the ETag may not change when released_at passes) and reports the release. The rescan waits one minute after released_at, so that GitLab has flipped the flag.

Cursor

FetchState.Cursor is JSON {"full_at":unix,"max_created_at":unix_ms,"upcoming_at":unix}: the time of the last validator-free scan, the newest created_at seen and the earliest pending upcoming release. It is a few dozen bytes. This source makes no per-release lookups: the list carries everything it reports.

Tokens

The token is read once per List call from WithToken or WithTokenEnv; a configured but empty token is an error, not an anonymous request (which cannot see private projects). It is sent as the PRIVATE-TOKEN header (personal, project and group access tokens) or, with WithBearerAuth, as "Authorization: Bearer" (OAuth 2 tokens), and only over https (or to a loopback host). It is held in a redacting type and never appears in an error or a log. The injected client is wrapped so that a redirect carrying the token to another host (including another port or a subdomain) or to plain http fails instead of being followed; net/http alone would forward the PRIVATE-TOKEN header to any host.

Index

Constants

View Source
const DefaultBaseURL = "https://gitlab.com"

DefaultBaseURL is gitlab.com. For a self-managed instance use its root URL, "https://HOST" (or "https://HOST/prefix" if GitLab is served under a relative URL root). A trailing "/api/v4" (any case) is accepted and ignored. A base URL with a query or a fragment is invalid.

View Source
const Kind = "gitlab-release"

Kind is the registry key of this source.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Source)

Option configures a Source.

func WithBearerAuth

func WithBearerAuth() Option

WithBearerAuth sends the token as "Authorization: Bearer" (OAuth 2 access tokens) instead of the default "PRIVATE-TOKEN" header (personal, project and group access tokens). GitLab accepts both forms for access tokens.

func WithClock

func WithClock(now func() time.Time) Option

WithClock overrides the clock used for the periodic full rescan and for the wake-up of upcoming releases.

func WithPageSize

func WithPageSize(n int) Option

WithPageSize overrides the page size (default 100, GitLab's maximum).

func WithToken

func WithToken(token string) Option

WithToken sets a fixed API token. A blank token makes List fail.

func WithTokenEnv

func WithTokenEnv(name string) Option

WithTokenEnv reads the token from the environment variable name on every List call (so a rotated token is picked up). If the variable is unset, empty or blank, List fails rather than silently falling back to anonymous access, which cannot see private projects.

type Source

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

Source implements source.Source for GitLab releases. It is safe for concurrent use.

func New

func New(baseURL string, hc *http.Client, opts ...Option) *Source

New returns a Source that sends requests to the GitLab instance at baseURL (DefaultBaseURL if empty) with hc, normally the netguard client. hc must not be nil. An invalid baseURL, or a token with a plain-http non-loopback base URL, does not panic: List returns the error.

New works on a shallow copy of hc whose CheckRedirect refuses to follow a redirect that would carry the token to another host or to plain http (net/http only compares host names, and forwards a custom header such as PRIVATE-TOKEN to any host, so it would keep the token across ports and subdomains).

func (*Source) Kind

func (*Source) Kind() string

Kind implements source.Source.

func (*Source) List

List implements source.Source.

func (*Source) Validate

func (*Source) Validate(t source.Target) error

Validate implements source.Source. It does no I/O.

Jump to

Keyboard shortcuts

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