ci

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ci defines TerraCI's CI-facing domain: persisted plan/report artifacts, review-comment contracts, and provider-shared CI config types.

Index

Constants

View Source
const CommentMarker = "<!-- terraci-plan-comment -->"

CommentMarker is used to identify TerraCI review comments for updates.

Variables

This section is empty.

Functions

func CommentEnabled added in v0.9.4

func CommentEnabled(cfg *MRCommentConfig) bool

CommentEnabled returns the effective enabled state for MR/PR comments. Nil config, nil Enabled, and missing config all default to true.

func HasCommentMarker added in v0.9.4

func HasCommentMarker(body string) bool

HasCommentMarker reports whether the provided body contains the TerraCI review-comment marker.

func ReportFilename added in v0.9.0

func ReportFilename(plugin string) string

ReportFilename returns the canonical artifact name for a plugin report.

func SaveJSON added in v0.7.4

func SaveJSON(serviceDir, filename string, v any) error

SaveJSON writes any value as indented JSON to {serviceDir}/{filename}.

func SaveReport added in v0.7.4

func SaveReport(serviceDir string, report *Report) error

SaveReport writes a plugin report as {serviceDir}/{plugin}-report.json.

Types

type CommentService

type CommentService interface {
	IsEnabled() bool
	UpsertComment(ctx context.Context, body string) error
}

CommentService defines the interface for posting plan summaries to PRs/MRs

type Image added in v0.9.4

type Image struct {
	// Name is the image name (e.g., "hashicorp/terraform:1.6")
	Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"description=Docker image name"`
	// Entrypoint overrides the default entrypoint.
	Entrypoint []string `yaml:"entrypoint,omitempty" json:"entrypoint,omitempty" jsonschema:"description=Override default entrypoint"`
}

Image defines a Docker image configuration for CI jobs.

func (*Image) HasEntrypoint added in v0.9.4

func (img *Image) HasEntrypoint() bool

HasEntrypoint returns true if entrypoint is configured.

func (*Image) String added in v0.9.4

func (img *Image) String() string

String returns the image name.

func (*Image) UnmarshalYAML added in v0.9.4

func (img *Image) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML supports both string shorthand ("image:1.0") and full object ({name: "image:1.0"}).

type MRCommentConfig added in v0.9.4

type MRCommentConfig struct {
	// Enabled enables MR comments (default: true when in MR pipeline).
	Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty" jsonschema:"description=Enable MR comments,default=true"`
	// OnChangesOnly only comments when there are changes.
	OnChangesOnly bool `` /* 126-byte string literal not displayed */
	// IncludeDetails includes full plan output in collapsible sections.
	IncludeDetails bool `` /* 151-byte string literal not displayed */
}

MRCommentConfig contains settings for MR/PR comments shared by CI providers.

type ModulePlan

type ModulePlan struct {
	ModuleID          string
	ModulePath        string
	Components        map[string]string
	Status            PlanStatus
	Summary           string // Compact summary e.g., "+2 ~1 -1"
	StructuredDetails string // Structured resource list by action (markdown)
	RawPlanOutput     string // Filtered raw plan output (diff only)
	Error             string // Error message if plan failed
	Duration          time.Duration
	// Cost estimation fields
	CostBefore float64 // Monthly cost before changes (USD)
	CostAfter  float64 // Monthly cost after changes (USD)
	CostDiff   float64 // Cost difference (after - before)
	HasCost    bool    // True if cost was calculated
}

ModulePlan represents terraform plan output for a single module

func (*ModulePlan) Get

func (p *ModulePlan) Get(name string) string

Get returns the value of a named component from the Components map.

type ModuleReport added in v0.7.4

type ModuleReport struct {
	ModulePath string  `json:"module_path"`
	CostBefore float64 `json:"cost_before,omitempty"`
	CostAfter  float64 `json:"cost_after,omitempty"`
	CostDiff   float64 `json:"cost_diff,omitempty"`
	HasCost    bool    `json:"has_cost,omitempty"`
	Error      string  `json:"error,omitempty"`
}

ModuleReport carries per-module enrichment data from a plugin report.

type PlanResult

type PlanResult struct {
	ModuleID          string            `json:"module_id"`
	ModulePath        string            `json:"module_path"`
	Components        map[string]string `json:"components,omitempty"`
	Status            PlanStatus        `json:"status"`
	Summary           string            `json:"summary"`
	StructuredDetails string            `json:"structured_details,omitempty"`
	RawPlanOutput     string            `json:"raw_plan_output,omitempty"`
	Error             string            `json:"error,omitempty"`
	ExitCode          int               `json:"exit_code"`
	// Cost estimation fields
	CostBefore float64 `json:"cost_before,omitempty"`
	CostAfter  float64 `json:"cost_after,omitempty"`
	CostDiff   float64 `json:"cost_diff,omitempty"`
	HasCost    bool    `json:"has_cost,omitempty"`
}

PlanResult represents a persisted CI artifact for a single module plan.

func (*PlanResult) Get

func (r *PlanResult) Get(name string) string

Get returns the value of a named component from the Components map.

type PlanResultCollection

type PlanResultCollection struct {
	Results     []PlanResult `json:"results"`
	PipelineID  string       `json:"pipeline_id,omitempty"`
	CommitSHA   string       `json:"commit_sha,omitempty"`
	GeneratedAt time.Time    `json:"generated_at"`
}

PlanResultCollection is the persisted CI artifact collection for a pipeline run.

func (*PlanResultCollection) ToModulePlans

func (c *PlanResultCollection) ToModulePlans() []ModulePlan

ToModulePlans converts plan results to ModulePlan for comment rendering

type PlanStatus

type PlanStatus string

PlanStatus represents the status of a terraform plan

const (
	PlanStatusPending   PlanStatus = "pending"
	PlanStatusRunning   PlanStatus = "running"
	PlanStatusSuccess   PlanStatus = "success"
	PlanStatusNoChanges PlanStatus = "no_changes"
	PlanStatusChanges   PlanStatus = "changes"
	PlanStatusFailed    PlanStatus = "failed"
)

func PlanStatusFromPlan added in v0.7.4

func PlanStatusFromPlan(hasChanges bool) PlanStatus

PlanStatusFromPlan determines the CI plan status from a parsed plan.

type Report added in v0.7.4

type Report struct {
	Plugin  string         `json:"plugin"`
	Title   string         `json:"title"`
	Status  ReportStatus   `json:"status"`
	Summary string         `json:"summary"`
	Body    string         `json:"body"`
	Modules []ModuleReport `json:"modules,omitempty"`
}

Report is a plugin-produced CI enrichment artifact consumed by summary flows. Plugins write reports as {serviceDir}/{plugin}-report.json.

func LoadReport added in v0.9.0

func LoadReport(path string) (*Report, error)

LoadReport reads a single report file from disk.

func LoadReports added in v0.9.0

func LoadReports(serviceDir string) ([]*Report, error)

LoadReports reads all *-report.json files from the service directory in deterministic filename order.

type ReportStatus added in v0.7.4

type ReportStatus string

ReportStatus indicates the outcome of a plugin's check.

const (
	ReportStatusPass ReportStatus = "pass"
	ReportStatusWarn ReportStatus = "warn"
	ReportStatusFail ReportStatus = "fail"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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