gitea

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 21 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) 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) 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) 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