Help us shape the future of Go! Take the 2026 Go Developer Survey

provider

package
v1.216.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package provider defines the CI/CD provider interface and related types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCheckRunName

func FormatCheckRunName(action, stack, component string) string

FormatCheckRunName creates a standardized check run name for Atmos. Deprecated: Use FormatStatusContext instead.

func FormatStatusContext

func FormatStatusContext(prefix string, parts ...string) string

FormatStatusContext creates a standardized status context string for Atmos. Parts are joined with "/" separator. Example: FormatStatusContext("atmos", "plan", "dev", "vpc") -> "atmos/plan/dev/vpc". Example: FormatStatusContext("atmos", "plan", "dev", "vpc", "add") -> "atmos/plan/dev/vpc/add".

Types

type ApplyOutputOptions

type ApplyOutputOptions struct {
	ExitCode int
	Success  bool
	Outputs  map[string]string
}

ApplyOutputOptions contains options for writing apply outputs.

type BaseResolution added in v1.214.0

type BaseResolution struct {
	// Ref is a git reference (branch/tag). Mutually exclusive with SHA.
	Ref string

	// SHA is a git commit hash. Mutually exclusive with Ref.
	SHA string

	// HeadSHA is the PR head commit SHA for upload correlation with Atmos Pro.
	// Populated for pull_request events from event.pull_request.head.sha.
	// Empty for non-PR events (push, merge_group, etc.).
	HeadSHA string

	// Source describes where the base was resolved from (for logging).
	Source string

	// EventType describes the CI event (e.g., "pull_request", "push").
	EventType string
}

BaseResolution contains the resolved base commit for affected detection.

type BranchStatus

type BranchStatus struct {
	// Branch is the branch name.
	Branch string

	// PullRequest is the PR associated with this branch (nil if none).
	PullRequest *PRStatus

	// CommitSHA is the HEAD commit SHA.
	CommitSHA string

	// Checks are the status checks for this branch/commit.
	Checks []*CheckStatus
}

BranchStatus contains status information for a specific branch.

type CheckRun

type CheckRun struct {
	// ID is the unique identifier for this check run.
	ID int64

	// Name is the check run name (e.g., "atmos/plan: plat-ue2-dev/vpc").
	Name string

	// Status is the current state of the check run.
	Status CheckRunState

	// Conclusion is the final conclusion (success, failure, etc.).
	Conclusion string

	// Title is a short title for the check run output.
	Title string

	// Summary is a markdown summary of the check run results.
	Summary string

	// DetailsURL is a link back to the CI run details.
	DetailsURL string

	// StartedAt is when the check run started.
	StartedAt time.Time

	// CompletedAt is when the check run completed.
	CompletedAt time.Time
}

CheckRun represents a status check on a commit (like Atlantis status checks).

type CheckRunState

type CheckRunState string

CheckRunState represents the state of a check run.

const (
	// CheckRunStatePending indicates the check run has not started.
	CheckRunStatePending CheckRunState = "pending"

	// CheckRunStateInProgress indicates the check run is in progress.
	CheckRunStateInProgress CheckRunState = "in_progress"

	// CheckRunStateSuccess indicates the check run completed successfully.
	CheckRunStateSuccess CheckRunState = "success"

	// CheckRunStateFailure indicates the check run failed.
	CheckRunStateFailure CheckRunState = "failure"

	// CheckRunStateError indicates an error occurred during the check run.
	CheckRunStateError CheckRunState = "error"

	// CheckRunStateCancelled indicates the check run was cancelled.
	CheckRunStateCancelled CheckRunState = "cancelled"
)

type CheckStatus

type CheckStatus struct {
	// Name is the check name.
	Name string

	// Status is the check status (e.g., "queued", "in_progress", "completed").
	Status string

	// Conclusion is the check conclusion (e.g., "success", "failure", "neutral").
	Conclusion string

	// DetailsURL is a link to the check details.
	DetailsURL string
}

CheckStatus contains status information for a single check.

func (*CheckStatus) CheckState

func (c *CheckStatus) CheckState() CheckStatusState

CheckState returns the simplified state for display.

type CheckStatusState

type CheckStatusState string

CheckStatusState represents the simplified state for display.

const (
	// CheckStatusStatePending indicates the check is pending or in progress.
	CheckStatusStatePending CheckStatusState = "pending"

	// CheckStatusStateSuccess indicates the check passed.
	CheckStatusStateSuccess CheckStatusState = "success"

	// CheckStatusStateFailure indicates the check failed.
	CheckStatusStateFailure CheckStatusState = "failure"

	// CheckStatusStateCancelled indicates the check was cancelled.
	CheckStatusStateCancelled CheckStatusState = "cancelled"

	// CheckStatusStateSkipped indicates the check was skipped.
	CheckStatusStateSkipped CheckStatusState = "skipped"
)

type Context

type Context struct {
	// Provider is the name of the CI provider (e.g., "github-actions").
	Provider string

	// RunID is the unique identifier for this CI run.
	RunID string

	// RunNumber is the run number (increments per workflow).
	RunNumber int

	// Workflow is the name of the workflow.
	Workflow string

	// Job is the name of the current job.
	Job string

	// Actor is the user or app that triggered the workflow.
	Actor string

	// EventName is the event that triggered the workflow (e.g., "push", "pull_request").
	EventName string

	// Ref is the git ref (e.g., "refs/heads/main").
	Ref string

	// Branch is the branch name (e.g., "main", "feature/foo").
	Branch string

	// SHA is the git commit SHA.
	SHA string

	// Repository is the full repository name (e.g., "owner/repo").
	Repository string

	// RepoOwner is the repository owner.
	RepoOwner string

	// RepoName is the repository name.
	RepoName string

	// PullRequest contains PR info if this is a pull request event.
	PullRequest *PRInfo
}

Context contains CI run metadata.

type CreateCheckRunOptions

type CreateCheckRunOptions struct {
	// Owner is the repository owner.
	Owner string

	// Repo is the repository name.
	Repo string

	// SHA is the commit SHA to create the check run on.
	SHA string

	// Name is the check run name (e.g., "atmos/plan: plat-ue2-dev/vpc").
	Name string

	// Status is the initial status (typically "queued" or "in_progress").
	Status CheckRunState

	// Title is a short title for the check run output.
	Title string

	// Summary is a markdown summary of the check run.
	Summary string

	// DetailsURL is a link back to the CI run.
	DetailsURL string

	// ExternalID is an optional external reference ID.
	ExternalID string
}

CreateCheckRunOptions contains options for creating a new check run.

type FileOutputWriter

type FileOutputWriter struct {
	OutputPath  string
	SummaryPath string
}

FileOutputWriter writes outputs to a file (like $GITHUB_OUTPUT).

func NewFileOutputWriter

func NewFileOutputWriter(outputPath, summaryPath string) *FileOutputWriter

NewFileOutputWriter creates a new FileOutputWriter.

func (*FileOutputWriter) WriteOutput

func (w *FileOutputWriter) WriteOutput(key, value string) error

WriteOutput writes a key-value pair to the output file. Format: key=value (single line) or key<<EOF\nvalue\nEOF (multiline).

func (*FileOutputWriter) WriteSummary

func (w *FileOutputWriter) WriteSummary(content string) error

WriteSummary appends content to the job summary file.

type NoopOutputWriter

type NoopOutputWriter struct{}

NoopOutputWriter is an OutputWriter that does nothing. Used when not running in CI or when CI outputs are disabled.

func (*NoopOutputWriter) WriteOutput

func (w *NoopOutputWriter) WriteOutput(_, _ string) error

WriteOutput implements OutputWriter.

func (*NoopOutputWriter) WriteSummary

func (w *NoopOutputWriter) WriteSummary(_ string) error

WriteSummary implements OutputWriter.

type OutputHelpers

type OutputHelpers struct {
	Writer OutputWriter
}

OutputHelpers provides helper methods for common CI output patterns.

func NewOutputHelpers

func NewOutputHelpers(writer OutputWriter) *OutputHelpers

NewOutputHelpers creates a new OutputHelpers.

func (*OutputHelpers) WriteApplyOutputs

func (h *OutputHelpers) WriteApplyOutputs(opts ApplyOutputOptions) error

WriteApplyOutputs writes standard apply output variables.

func (*OutputHelpers) WritePlanOutputs

func (h *OutputHelpers) WritePlanOutputs(opts PlanOutputOptions) error

WritePlanOutputs writes standard plan output variables.

type OutputWriter

type OutputWriter interface {
	// WriteOutput writes a key-value pair to CI outputs (e.g., $GITHUB_OUTPUT).
	WriteOutput(key, value string) error

	// WriteSummary writes content to the job summary (e.g., $GITHUB_STEP_SUMMARY).
	WriteSummary(content string) error
}

OutputWriter writes CI outputs (environment variables, job summaries, etc.).

type PRInfo

type PRInfo struct {
	// Number is the PR number.
	Number int

	// HeadRef is the source branch.
	HeadRef string

	// BaseRef is the target branch.
	BaseRef string

	// URL is the PR URL.
	URL string
}

PRInfo contains pull request metadata.

type PRStatus

type PRStatus struct {
	// Number is the PR number.
	Number int

	// Title is the PR title.
	Title string

	// Branch is the head branch name.
	Branch string

	// BaseBranch is the target branch name.
	BaseBranch string

	// URL is the PR URL.
	URL string

	// Checks are the status checks for this PR.
	Checks []*CheckStatus

	// AllPassed is true if all checks have passed.
	AllPassed bool
}

PRStatus contains status information for a pull request.

type PlanOutputOptions

type PlanOutputOptions struct {
	HasChanges        bool
	HasAdditions      bool
	AdditionsCount    int
	ChangesCount      int
	HasDestructions   bool
	DestructionsCount int
	ExitCode          int
	ArtifactKey       string
}

PlanOutputOptions contains options for writing plan outputs.

type Provider

type Provider interface {
	// Name returns the provider name (e.g., "github-actions", "generic").
	Name() string

	// Detect returns true if this provider is active in the current environment.
	Detect() bool

	// Context returns CI metadata (run ID, PR info, etc.).
	Context() (*Context, error)

	// GetStatus returns PR/commit status for the current branch.
	GetStatus(ctx context.Context, opts StatusOptions) (*Status, error)

	// CreateCheckRun creates a new check run on a commit (like Atlantis status checks).
	CreateCheckRun(ctx context.Context, opts *CreateCheckRunOptions) (*CheckRun, error)

	// UpdateCheckRun updates an existing check run.
	UpdateCheckRun(ctx context.Context, opts *UpdateCheckRunOptions) (*CheckRun, error)

	// OutputWriter returns a writer for CI outputs ($GITHUB_OUTPUT, etc.).
	OutputWriter() OutputWriter

	// ResolveBase returns the base commit for affected detection.
	// Returns nil if the provider cannot determine the base.
	ResolveBase() (*BaseResolution, error)
}

Provider represents a CI/CD provider (GitHub Actions, GitLab CI, etc.).

type Status

type Status struct {
	// Repository is the full repository name (e.g., "owner/repo").
	Repository string

	// CurrentBranch contains status for the current branch.
	CurrentBranch *BranchStatus

	// CreatedByUser contains PRs created by the authenticated user.
	CreatedByUser []*PRStatus

	// ReviewRequests contains PRs requesting review from the user.
	ReviewRequests []*PRStatus
}

Status represents the CI status for display (like gh pr status).

type StatusOptions

type StatusOptions struct {
	// Owner is the repository owner.
	Owner string

	// Repo is the repository name.
	Repo string

	// Branch is the branch to check (optional, defaults to current branch).
	Branch string

	// SHA is the commit SHA to check (optional, defaults to HEAD).
	SHA string

	// IncludeUserPRs includes PRs created by the authenticated user.
	IncludeUserPRs bool

	// IncludeReviewRequests includes PRs requesting review from the user.
	IncludeReviewRequests bool
}

StatusOptions contains options for fetching CI status.

type UpdateCheckRunOptions

type UpdateCheckRunOptions struct {
	// Owner is the repository owner.
	Owner string

	// Repo is the repository name.
	Repo string

	// SHA is the commit SHA (used for fallback creation when no prior CreateCheckRun).
	SHA string

	// Name is the check run name (used as correlation key).
	Name string

	// Status is the new status.
	Status CheckRunState

	// Conclusion is the final conclusion (required when status is "completed").
	Conclusion string

	// Title is the output title (distinct from the check run name).
	Title string

	// Summary is an updated markdown summary.
	Summary string

	// DetailsURL is a link back to the CI run.
	DetailsURL string

	// CompletedAt is when the check run completed.
	CompletedAt *time.Time
}

UpdateCheckRunOptions contains options for updating an existing check run.

Jump to

Keyboard shortcuts

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