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 IsNotFound ¶
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 ¶
APIError is a host's refusal, with the status kept so callers can tell a wrong token from a missing repository without reading English.
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 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.
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.