provider

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package provider talks to the git hosts' APIs — the part of a promotion that plain git cannot do.

The boundary is deliberate and narrow. Cloning, committing and pushing work against any host over HTTPS or SSH with no provider code at all, and Hecate does them that way. What needs an API is the review: opening a pull request, learning whether it merged, and reporting a commit status. That is all this package covers, which is why adding a host is small.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAuth

func IsAuth(err error) bool

IsAuth reports whether the host rejected the credentials.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether the host says the thing is not there. On GitHub a private repository reached with an unauthorised token also answers 404, which is the same answer for a human: check the token and the name.

Types

type APIError

type APIError struct {
	Status  int
	Method  string
	Path    string
	Message string
}

APIError is a host's refusal, with the status kept so callers can tell a wrong token from a missing repository without reading English.

func (*APIError) Error

func (e *APIError) Error() string

type CommitState

type CommitState string

CommitState is the outcome being reported against a commit.

Three, not the union of what the hosts accept. GitHub also has `error` and GitLab has `running` and `canceled`; a crossing is starting, it worked, or it did not, and offering states with no Hecate meaning would only invite disagreement about which to use.

const (
	// StatePending means the crossing is under way.
	StatePending CommitState = "Pending"
	// StateSuccess means it finished and the environment converged.
	StateSuccess CommitState = "Success"
	// StateFailure means it did not.
	StateFailure CommitState = "Failure"
)

type CommitStatus

type CommitStatus struct {
	Repo Repo
	// SHA is the commit being reported on — the one Flux applied, not the one
	// that built the image. Hecate does not know the latter.
	SHA string
	// State is the outcome.
	State CommitState
	// Context names the check, and is what the host de-duplicates on. One per
	// Gate, so `production` and `staging` do not overwrite each other.
	Context string
	// Description is the one-line summary shown beside the check.
	Description string
	// TargetURL is where a human goes for detail. Optional.
	TargetURL string
}

CommitStatus is an outcome to report against a commit.

type Config

type Config struct {
	// BaseURL is the API root. Empty means the public host's. Set it for GitHub
	// Enterprise Server and self-managed GitLab — the organisations that care
	// most about promotion gates are mostly not on the public hosts.
	BaseURL string
	// Token authenticates. A personal, project or installation access token.
	Token string
}

Config is what a provider needs to reach a host.

type Kind

type Kind string

Kind identifies a host's API flavour.

const (
	GitHub Kind = "github"
	GitLab Kind = "gitlab"
)

func KindFor

func KindFor(host string) Kind

KindFor guesses the API flavour from a host. It only knows the two public hosts by name: a self-managed GitLab or a GitHub Enterprise Server is indistinguishable by hostname, so those must say which they are.

type Provider

type Provider interface {
	// Kind is which host flavour this is.
	Kind() Kind
	// EnsurePullRequest opens a pull request, or returns the one already open
	// for the same head branch.
	//
	// Not "Create": a step is re-entrant (D19), so it will call this again
	// after a requeue, and a second identical pull request is worse than none.
	EnsurePullRequest(ctx context.Context, spec PullRequestSpec) (*PullRequest, error)
	// PullRequest reads one back.
	PullRequest(ctx context.Context, repo Repo, number int) (*PullRequest, error)
	// SetCommitStatus reports an outcome against a commit.
	//
	// Idempotent, because steps are re-entrant (D19): reporting the same state
	// twice must succeed rather than fail the crossing over a duplicate.
	SetCommitStatus(ctx context.Context, status CommitStatus) error
}

Provider is a git host's API, as far as a promotion needs it.

func New

func New(kind Kind, cfg Config) (Provider, error)

New builds a provider.

A switch rather than a registry: there are two hosts, and a registration mechanism for two implementations is a mechanism to maintain for nothing.

type PullRequest

type PullRequest struct {
	Number int
	URL    string
	State  State
	// MergeCommit is the commit the merge produced, once it has merged. It is
	// what a later flux-wait waits for — the branch commit never lands on the
	// base branch under its own hash when the host squashes.
	MergeCommit string
	// Head is the branch the change is on.
	Head string
}

PullRequest is a change awaiting review. GitLab calls it a merge request; the shape is the same and the vocabulary difference stops at the API client.

type PullRequestSpec

type PullRequestSpec struct {
	Repo   Repo
	Head   string
	Base   string
	Title  string
	Body   string
	Labels []string
}

PullRequestSpec is what to open.

type Repo

type Repo struct {
	// Host is the API host, e.g. github.com or gitlab.example.com.
	Host string
	// Owner is the user, organisation or group path. GitLab groups nest, so
	// this can contain slashes.
	Owner string
	// Name is the repository itself.
	Name string
}

Repo identifies a repository on a host.

func ParseRepo

func ParseRepo(cloneURL string) (Repo, error)

ParseRepo pulls a repository out of a git clone URL, in either of the two forms people actually write:

https://github.com/acme/fleet.git
git@gitlab.example.com:group/sub/fleet.git

func (Repo) Slug

func (r Repo) Slug() string

Slug is owner/name, the form both APIs use in paths.

func (Repo) String

func (r Repo) String() string

type State

type State string

State is where a pull request has got to.

const (
	Open   State = "Open"
	Merged State = "Merged"
	Closed State = "Closed"
)

Jump to

Keyboard shortcuts

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