Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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.
Types ¶
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
}
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.
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
}
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
Description 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
}
Status holds the information to post as a commit status.
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.