gitea

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: 26 Imported by: 0

Documentation

Overview

Package gitea resolves versions from a Gitea or Forgejo forge's tags and releases. One provider serves every instance of the API: Codeberg (the default host), forgejo.org, and any self-managed Gitea/Forgejo, selected by the host key. Discovery is a single cached REST listing per marker; selection, cooldown, and filtering stay with the framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Login

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

Login authenticates clover with a Gitea/Forgejo host via the OAuth authorization-code flow with PKCE (RFC 8252): it binds a loopback listener, opens the browser to the host's authorize page through prompt, captures the redirected code, exchanges it for tokens, and persists them under the host so the credential chain finds them. host and clientID default to codeberg.org and Gitea's built-in public "tea" application. Gitea has no device flow, so this browser flow is the interactive login; it needs a local browser (not headless), which is fine for a one-time login command.

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 a minted login from, for tests.

func WithToken

func WithToken(tok string) Option

WithToken injects a PAT credential directly, for tests exercising the authenticated path 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 away from ambient env vars (see staticCredential), 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 Gitea/Forgejo project's tags or releases over a single cached REST client shared across a run. The host is per-marker (the API is the same on every instance), so the client is host-agnostic, each request carries its own absolute URL, and the credential is resolved per host - an env-var PAT is host-independent, but a token minted by `clover login` is stored under the host it authenticated.

func New

func New(opts ...Option) *Provider

New returns the Gitea provider. A token comes from CLOVER_GITEA_TOKEN, a login minted by `clover login gitea` (stored per host), or anonymous access applies. The default keychain store is wired only on the real transport: a test transport keeps auth explicit (WithToken/WithStore), so the machine's stored token never leaks into a test.

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, without verifying it over the network or blocking on a prompt. It sees the host-independent PAT and a login stored under the default host; a login under a non-default host is keyed by host and only resolved at discovery, so this may under-report for those. Absence is reported as errAnonymous - informational, not fatal, since anonymous reads still work.

func (*Provider) Branches added in v0.3.10

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

Branches lists the repository's branches with their tip commits, for matching an allowed-branch pattern and the tip-equality fast path.

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. An expired login still counts when it carries a refresh token, since the next request renews it.

func (*Provider) Dated added in v0.2.8

func (p *Provider) Dated()

Dated marks the listing as date-bearing: releases carry a publication date. Bare tags do not, and fall 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 repository'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. Gitea serves an uploaded asset's bytes at its browser URL (/attachments/<uuid>), which honors the API credential - its asset API endpoint returns JSON metadata, not bytes - so the browser URL is fetched with the credential attached whenever it sits on the forge host itself. An external-type asset points off-host and must not receive the token, and any redirect off the forge 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 owner/name repository and its landing page.

func (*Provider) Keys

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

Keys reports the directive keys Gitea 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, via the compare API.

func (*Provider) Resource

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

Resource validates a directive into a Gitea resource. The repository is a strict owner/name: Gitea and Forgejo organize repos under a flat owner, with no nested subgroups, unlike GitLab.

func (*Provider) URL

URL builds the web page for a resolved candidate: the source-at-tag page for the candidate's ref, which exists for every tag whether or not it has a release. Empty when the ref is unknown.

Jump to

Keyboard shortcuts

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