provider

package
v1.223.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 9 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 Annotation added in v1.222.0

type Annotation struct {
	Path      string
	StartLine int
	EndLine   int
	Level     AnnotationLevel
	Title     string
	Message   string
}

Annotation is a provider-neutral, line-anchored finding. Scanner hooks build these from parsed SARIF findings and hand them to the active provider's Annotator; the provider renders them inline on the change (GitHub: workflow annotations on the PR diff). StartLine is 1-based; 0 means "unknown", in which case the annotation anchors at the file level.

type AnnotationLevel added in v1.222.0

type AnnotationLevel string

AnnotationLevel is the severity bucket a CI annotation renders as. The values mirror the three levels GitHub Actions workflow commands support (`::error` / `::warning` / `::notice`); other providers map them to their nearest equivalent.

const (
	// AnnotationError is the highest level (GitHub: ::error).
	AnnotationError AnnotationLevel = "error"
	// AnnotationWarning is the middle level (GitHub: ::warning).
	AnnotationWarning AnnotationLevel = "warning"
	// AnnotationNotice is the lowest level (GitHub: ::notice).
	AnnotationNotice AnnotationLevel = "notice"
)

type Annotator added in v1.222.0

type Annotator interface {
	// Annotate renders the given annotations in the current run. It is
	// best-effort from the caller's perspective: a returned error is logged,
	// never fatal.
	Annotate(annotations []Annotation) error
}

Annotator is an optional capability for providers that can render line-anchored annotations in the current run (GitHub Actions: `::error` / `::warning` workflow commands shown inline on the PR diff). Providers implement this when their platform surfaces per-line annotations from log output without needing GitHub Advanced Security.

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

	// TargetBranch is the PR target branch name (e.g., "main") when known.
	// Used by callers to recover from missing local refs by running a
	// targeted git fetch. Empty when the event has no notion of a target
	// branch (e.g., push events on the default branch).
	TargetBranch 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 CacheProvider added in v1.222.0

type CacheProvider interface {
	// Cache returns the provider's cache backend.
	Cache() (cache.Backend, error)
}

CacheProvider is an optional capability for CI providers that expose a remote build cache (for example, the GitHub Actions cache). Providers implement this when their platform offers a documented cache store reachable from within a run. Cache() returns errUtils.ErrCacheUnavailable when the provider is active but the cache cannot be reached in the current environment (e.g. the runtime cache token is absent).

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 Comment added in v1.218.0

type Comment struct {
	// ID is the provider-specific comment ID.
	ID int64

	// URL is the HTML URL of the comment (if known).
	URL string

	// Body is the final body that was written.
	Body string

	// Created indicates whether a new comment was created (true) or an
	// existing one was updated (false).
	Created bool
}

Comment represents a PR/MR comment returned by PostComment.

type CommentBehavior added in v1.218.0

type CommentBehavior string

CommentBehavior controls how PostComment reconciles an incoming comment against existing comments on the same PR/MR.

const (
	// CommentBehaviorCreate always creates a new comment, even if a comment
	// with the same marker already exists.
	CommentBehaviorCreate CommentBehavior = "create"

	// CommentBehaviorUpdate updates an existing comment matched by marker.
	// Returns ErrCICommentNotFound when no matching comment exists.
	CommentBehaviorUpdate CommentBehavior = "update"

	// CommentBehaviorUpsert updates an existing comment matched by marker,
	// creating a new one when none matches. This is the default.
	CommentBehaviorUpsert CommentBehavior = "upsert"
)

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

	// ElevatedEvent reports whether the triggering event runs with the base
	// repository's secrets while the workspace may contain untrusted fork
	// content (GitHub's pull_request_target and workflow_run). Providers set
	// this so the provider-agnostic fork-checkout safety gate can refuse to
	// clone fork content under these events without an explicit opt-in.
	// See docs/prd/native-ci/framework/fork-pr-trust-gate.md.
	ElevatedEvent bool

	// 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

	// ServerURL is the base URL of the SCM host running this CI
	// (e.g., "https://github.com" or a GitHub Enterprise URL).
	// Empty when the provider cannot determine it.
	ServerURL string

	// CloneURL is the URL to clone the current repository, used by
	// `atmos git clone` for CI checkout replacement. Each provider
	// constructs it from its own metadata; empty when the provider
	// cannot determine it.
	CloneURL 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 DebugModeDetector added in v1.220.0

type DebugModeDetector interface {
	// IsDebugMode reports whether the current run has debug logging enabled
	// at the CI provider level. Callers use this to auto-promote their own
	// log level.
	IsDebugMode() bool
}

DebugModeDetector is an optional capability for providers that expose a "debug mode" signal set at the runner / step / job level (for example, GitHub Actions' ACTIONS_RUNNER_DEBUG and ACTIONS_STEP_DEBUG). Providers implement this when their platform has a documented way for users to opt into verbose diagnostic logging for a 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 LogGrouper added in v1.223.0

type LogGrouper interface {
	// StartLogGroup opens a collapsible log group with the given title.
	StartLogGroup(title string) error

	// EndLogGroup closes the current log group.
	EndLogGroup() error
}

LogGrouper is an optional capability for providers that can group log output in the current run (for example, GitHub Actions' ::group:: workflow command).

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 PostCommentOptions added in v1.218.0

type PostCommentOptions struct {
	// Owner is the repository owner (GitHub) or namespace (GitLab).
	Owner string

	// Repo is the repository name.
	Repo string

	// PRNumber is the pull/merge request number.
	PRNumber int

	// Marker is an HTML/Markdown marker string used to find existing comments
	// on repeat runs. It must appear in Body. Typical value:
	//   "<!-- atmos:ci:plan:<component>:<stack> -->".
	Marker string

	// Body is the full comment body (including Marker).
	Body string

	// Behavior controls create/update/upsert semantics. Empty defaults to
	// CommentBehaviorUpsert.
	Behavior CommentBehavior
}

PostCommentOptions contains options for posting or upserting a PR/MR comment.

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)

	// PostComment posts or upserts a PR/MR comment. Providers that do not
	// support comments should return errUtils.ErrCIOperationNotSupported.
	// Implementations use the marker string to find and update existing
	// comments on repeat runs (upsert); callers embed the marker in Body.
	PostComment(ctx context.Context, opts *PostCommentOptions) (*Comment, 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 SARIFReport added in v1.222.0

type SARIFReport struct {
	Body     []byte
	Category string
}

SARIFReport is a provider-neutral request to publish a SARIF document to the provider's security-findings store. Body is the raw SARIF 2.1.0 bytes the scanner produced (passed through unmodified for full fidelity); Category identifies the analysis so multiple uploads for the same commit (e.g. one per component) coexist instead of overwriting each other.

type SARIFReporter added in v1.222.0

type SARIFReporter interface {
	// ReportSARIF uploads the SARIF document to the provider's findings store.
	// Best-effort from the caller's perspective; a returned error is logged,
	// never fatal.
	ReportSARIF(ctx context.Context, report SARIFReport) error
}

SARIFReporter is an optional capability for providers that ingest SARIF into a security-findings store (GitHub: Code Scanning / the Security tab — which requires GitHub Advanced Security on private repos). Providers implement this when their platform exposes a documented SARIF ingestion endpoint.

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