Documentation
¶
Index ¶
- func ContextForRun(target string) string
- func ContextForStack(target, stack string) string
- func FailureDescription(err error) string
- func IsRateLimited(err error) bool
- func Post(ctx context.Context, provider Provider, ...) error
- func SuccessDescription(startedAt, finishedAt time.Time) string
- func WithSingleAttempt(ctx context.Context) context.Context
- type Backend
- type Outcome
- type Provider
- type Request
- type RequestParams
- type State
- type Status
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextForRun ¶ added in v0.129.0
ContextForRun keeps the configuration target in reports without a stack name.
func ContextForStack ¶ added in v0.98.0
func FailureDescription ¶ added in v0.115.0
FailureDescription normalizes err into a single-line, Unicode-safe description suitable for a commit status. Internal whitespace (including newlines) is collapsed to single spaces, and the result is truncated to at most maxDescriptionLength runes. A nil error returns "Failed".
func IsRateLimited ¶ added in v0.124.0
IsRateLimited reports whether err is a provider's rate limit response: 429, or a 403 whose message mentions a rate limit (GitHub's primary and secondary limits).
func Post ¶
func Post(ctx context.Context, provider Provider, apiBaseURL, repoURL, repoFullName, commitSHA, token string, status Status) error
Post posts a commit status to the appropriate Git provider. When provider is ProviderAuto ("") the provider is detected from repoURL. When apiBaseURL is non-empty, it overrides the inferred SCM API base URL. Returns nil (silently no-op) when token or commitSHA is empty.
func SuccessDescription ¶ added in v0.122.1
SuccessDescription describes a successful deployment with its duration. It omits the duration when either timestamp is missing or they are out of order.
func WithSingleAttempt ¶ added in v0.124.0
WithSingleAttempt returns a context whose commit status writes are sent once, without retries. Best-effort updates use it so they never wait on backoff or spend requests against a provider's rate limit.
Types ¶
type Backend ¶ added in v0.124.0
type Backend string
Backend selects the provider API used to publish a reporting attempt.
type Outcome ¶ added in v0.124.0
type Outcome string
Outcome distinguishes lifecycle events that legacy commit statuses conflate.
func FailureOutcome ¶ added in v0.124.0
FailureOutcome returns the Outcome corresponding to err, or "" if err is not a recognized failure type. This is used to normalize SCM API errors into commit status outcomes.
type Provider ¶
type Provider string
Provider identifies which SCM API to use when posting a commit status. The zero value ("") means auto-detect from the repository URL.
const ( // ProviderAuto detects the provider from the repository URL (default). ProviderAuto Provider = "" // ProviderGitHub targets the GitHub REST API. // For github.com the public API is used; for any other host the GitHub // Enterprise Server endpoint (/api/v3) is used instead. ProviderGitHub Provider = "github" // ProviderGitLab targets the GitLab API v4. ProviderGitLab Provider = "gitlab" // ProviderGitea targets the Gitea/Forgejo API v1. ProviderGitea Provider = "gitea" // ProviderAzureDevOps targets the Azure DevOps Git statuses API. ProviderAzureDevOps Provider = "azuredevops" )
func ParseProvider ¶
ParseProvider converts a string (e.g. from an env var) to a Provider. Returns an error when the value is non-empty, not "auto", and not a known provider.
type Request ¶ added in v0.115.0
type Request struct {
Provider Provider
APIBaseURL string
RepoURL string
RepoFullName string
CommitSHA string
Token string
Context string
Target *Target
}
Request is a fully-resolved commit status request, ready to Post or Get.
func ResolveRequest ¶ added in v0.115.0
func ResolveRequest(logger *slog.Logger, params RequestParams) (Request, bool)
ResolveRequest resolves a Request from params, applying credential precedence (a resolved scoped/GitHub App token takes priority over params.AccessToken), repository URL/full name fallback, and provider/API URL/context defaults. logger receives Debug/Warn diagnostics for skip reasons and token-resolution failures.
ok is false when the caller should skip posting/getting a commit status: commit statuses are disabled, the source is not Git, no commit SHA is available, or no credentials are configured.
func (Request) Get ¶ added in v0.115.0
Get returns the latest commit status for the resolved request's context.
func (Request) Post ¶ added in v0.115.0
Post posts status using the resolved request's provider/repository/credentials. status.Context is overridden with the request's resolved Context.
func (Request) SupportsProgress ¶ added in v0.124.0
SupportsProgress reports whether the request's provider can show the phase of a running deployment. GitLab cannot: it rejects a running status for a pipeline that is already running, so its description cannot change.
type RequestParams ¶ added in v0.115.0
type RequestParams struct {
// Enabled mirrors the application-level "post commit statuses" toggle
// (e.g. app.Config.GitCommitStatus). When false, ResolveRequest always skips.
Enabled bool
// SourceIsGit must be true for commit statuses to be posted/read; OCI (or
// any other non-Git) sources are always skipped.
SourceIsGit bool
// SourceURL is the repository URL used both for credential resolution and,
// when PayloadWebURL/PayloadFullName are empty, as the repository identity.
SourceURL string
// CommitSHA is the resolved commit the status applies to. Empty skips.
CommitSHA string
// PayloadWebURL optionally overrides SourceURL as the repository URL (e.g.
// the browsable web URL from a webhook payload).
PayloadWebURL string
// PayloadFullName optionally overrides the "owner/repo" full name derived
// from the repository URL (e.g. from a webhook payload).
PayloadFullName string
// ProviderOverride is the raw configured SCM provider (e.g. app.Config.GitScmProvider).
// Empty/"auto" auto-detects the provider from the repository URL.
ProviderOverride string
// APIBaseURL optionally overrides the inferred SCM API base URL (e.g. app.Config.GitScmApiUrl).
APIBaseURL string
// AccessToken is the configured fallback access token (e.g. app.Config.GitAccessToken),
// used when no scoped/GitHub App credential is resolved for SourceURL.
AccessToken string
// ContextName is the commit status context label (e.g. "doco-cd/demo").
// Empty defaults to DeployContext.
ContextName string
// Target pins an already-started reporting attempt, including handovers.
Target *Target
// Scope separates deployments with the same check name on different Docker contexts.
Scope string
}
RequestParams holds the raw inputs needed to resolve a commit status Request. Callers (e.g. the source and stages packages) supply the relevant subset of their own application configuration and per-deployment context; RequestParams intentionally avoids depending on any higher-level config type to keep this package free of import cycles.
type State ¶
type State string
State represents the commit status state sent to the Git provider.
const ( StatePending State = "pending" StateSuccess State = "success" StateFailure State = "failure" StateError State = "error" BaseContext = "doco-cd" DeployContext = BaseContext + "/deploy" )
type Status ¶
type Status struct {
State State
Outcome Outcome
Description string
// Summary optionally explains the status in Markdown. Only GitHub check
// runs show it, other providers only show the description.
Summary string
// Context is the label shown in the Git UI (e.g. "doco-cd/demo").
// Defaults to BaseContext when empty.
Context string
TargetURL string // optional link to deployment logs
// Phase is the current phase of a running deployment, e.g. "pulling
// images". GitHub check runs show it in their title.
Phase string
}
Status holds the information to post as a commit status.
func FailureStatus ¶ added in v0.128.0
FailureStatus keeps a short description for commit statuses and the full error as literal text for GitHub check summaries.
func Get ¶
func Get(ctx context.Context, provider Provider, apiBaseURL, repoURL, repoFullName, commitSHA, token, contextName string) (Status, bool, error)
Get returns the latest commit status for the requested context. When provider is ProviderAuto ("") the provider is detected from repoURL. When apiBaseURL is non-empty, it overrides the inferred SCM API base URL. Returns found=false when token, commitSHA, or matching status is missing.
func ProgressStatus ¶ added in v0.124.0
ProgressStatus returns the status of a running deployment in phase, for example "In Progress: pulling images".
type Target ¶ added in v0.124.0
type Target struct {
Backend Backend `json:"backend"`
ExternalID string `json:"external_id,omitempty"`
CheckRunID int64 `json:"check_run_id,omitempty"`
AppID string `json:"app_id,omitempty"`
Scope string `json:"scope,omitempty"`
StartedAt time.Time `json:"started_at,omitzero"`
}
Target identifies a reporting attempt without storing its credentials.