gitsource

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package gitsource loads a catalog from a git ref: a shallow fetch into a temporary directory with the git CLI, then catalog.LoadDir on the catalog's directory in it, with the commit as the snapshot's SHA (design/workstreams/dispatcher-core/LLD/catalog.md §Loading). Head resolves a ref to its commit with git ls-remote, for catalog-sync's polling; HeadAuth and LoadAuth do the same on a private repository with a token (Auth).

Errors never carry credentials: user info in the repository URL (a token in https://x-access-token:<token>@host/…) and an Auth token are redacted from every error message.

It is the one part of catalog loading that runs a process and touches the network, so it is kept out of the pure catalog package. It shells out to git rather than linking go-git, which isn't on the dependency allow-list.

Index

Constants

This section is empty.

Variables

View Source
var ErrGit = errors.New("git")

ErrGit is wrapped by every failure to fetch the ref (git missing, network, unknown ref).

Functions

func Head(ctx context.Context, repoURL, ref string) (string, error)

Head returns the commit ref points to in repoURL, with git ls-remote (no clone). A ref that is already a full commit SHA is returned as is. A branch wins over a tag of the same name, and an annotated tag resolves to its commit. Errors wrap ErrGit (or the context's error) and carry no credentials.

func HeadAuth

func HeadAuth(ctx context.Context, repoURL, ref string, auth Auth) (_ string, err error)

HeadAuth is Head on a repository that needs a credential: auth's token goes to git as an Authorization header scoped to repoURL (Auth.config), so the URL must be http(s) and carry no user info. A zero Auth is Head. The token never appears in an error.

func IsCommit

func IsCommit(ref string) bool

IsCommit reports whether ref is a full commit SHA, which Head returns as is (no git, no credential needed).

func Load

func Load(ctx context.Context, repoURL, ref, dir string, opts catalog.Options) (*catalog.Catalog, []catalog.Error, error)

Load fetches ref (a branch, tag or commit) of repoURL at depth 1 into a temporary directory, loads the catalog in its subdirectory dir ("catalog"; "" or "." for the repo root) and removes the checkout. The snapshot's SHA is the fetched commit. The []Error is LoadDir's; err is set only when the ref couldn't be fetched (wrapping ErrGit) or dir doesn't exist.

func LoadAuth added in v0.3.0

func LoadAuth(ctx context.Context, repoURL, ref, dir string, opts catalog.Options, auth Auth) (_ *catalog.Catalog, _ []catalog.Error, err error)

LoadAuth is Load from a repository that needs a credential: the fetch sends auth's token as HeadAuth does (an Authorization header scoped to repoURL, in git's environment), so the URL must be http(s) and carry no user info. A zero Auth is Load. The token never appears in an error.

func RedactURL

func RedactURL(repoURL string) string

RedactURL drops the user info (a token or password) from a repository URL, for logs and status. Other forms (scp-like ssh, plain paths) are returned unchanged.

Types

type Auth

type Auth struct {
	Username string
	Token    string
}

Auth is an HTTP credential for a private repository: a token and the username that goes with it ("x-access-token" for a GitHub installation token, the default). The zero value is anonymous.

Jump to

Keyboard shortcuts

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