Documentation
¶
Overview ¶
Package plugin provides the compile-time plugin system for TerraCi. Plugins register themselves via init() and blank imports, following the same pattern as database/sql drivers and Caddy modules.
Index ¶
- func ByCapability[T Plugin]() []T
- func CollectContributions() []*pipeline.Contribution
- func Register(p Plugin)
- func Reset()
- type AppContext
- type ChangeDetectionProvider
- type CommandProvider
- type CommentSection
- type ConfigProvider
- type ExecutionContext
- type GeneratorProvider
- type InitContribution
- type InitContributor
- type InitField
- type InitGroupSpec
- type InitOption
- type InitState
- type Initializable
- type PipelineContributor
- type Plugin
- type StateMap
- type SummaryContributor
- type VersionProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByCapability ¶
func ByCapability[T Plugin]() []T
ByCapability returns all plugins that implement the given capability interface.
func CollectContributions ¶ added in v0.7.3
func CollectContributions() []*pipeline.Contribution
CollectContributions gathers pipeline contributions from all PipelineContributor plugins.
Types ¶
type AppContext ¶
type AppContext struct {
Config *config.Config
WorkDir string
ServiceDir string // resolved absolute path to project service directory
Version string
}
AppContext is the public API available to plugins.
type ChangeDetectionProvider ¶
type ChangeDetectionProvider interface {
Plugin
DetectChangedModules(ctx context.Context, appCtx *AppContext, baseRef string, moduleIndex *discovery.ModuleIndex) (changed []*discovery.Module, changedFiles []string, err error)
DetectChangedLibraries(ctx context.Context, appCtx *AppContext, baseRef string, libraryPaths []string) ([]string, error)
}
ChangeDetectionProvider detects changed modules from git (or other VCS).
func ResolveChangeDetector ¶ added in v0.7.3
func ResolveChangeDetector() (ChangeDetectionProvider, error)
ResolveChangeDetector returns the active ChangeDetectionProvider. Priority: single registered → configured → first available.
type CommandProvider ¶
type CommandProvider interface {
Plugin
Commands(ctx *AppContext) []*cobra.Command
}
CommandProvider adds CLI subcommands to TerraCi.
type CommentSection ¶
type CommentSection struct {
Order int // Lower = rendered first
Title string // Section heading
Content string // Markdown content
}
CommentSection is an additional section contributed by a plugin to the PR/MR comment.
type ConfigProvider ¶
type ConfigProvider interface {
Plugin
ConfigKey() string
NewConfig() any
SetConfig(cfg any) error
IsConfigured() bool // true if SetConfig was called with explicit config
}
ConfigProvider declares a config section under "plugins:" in .terraci.yaml.
type ExecutionContext ¶
type ExecutionContext struct {
// PlanResults is the collected plan result data, available for enrichment.
PlanResults *ci.PlanResultCollection
// Sections holds additional markdown sections contributed by plugins.
Sections []CommentSection
// Data holds arbitrary typed data for inter-plugin communication.
Data map[string]any
// contains filtered or unexported fields
}
ExecutionContext holds shared mutable state during command execution. Plugins read and write to this during the summary phase.
func NewExecutionContext ¶
func NewExecutionContext(plans *ci.PlanResultCollection) *ExecutionContext
NewExecutionContext creates an ExecutionContext from plan results.
func (*ExecutionContext) AddSection ¶
func (e *ExecutionContext) AddSection(section CommentSection)
AddSection adds a comment section from a plugin.
func (*ExecutionContext) GetData ¶
func (e *ExecutionContext) GetData(key string) (any, bool)
GetData retrieves a value set by another plugin.
func (*ExecutionContext) SetData ¶
func (e *ExecutionContext) SetData(key string, value any)
SetData stores a value for inter-plugin communication.
type GeneratorProvider ¶
type GeneratorProvider interface {
Plugin
ProviderName() string
DetectEnv() bool
NewGenerator(ctx *AppContext, depGraph *graph.DependencyGraph, modules []*discovery.Module) pipeline.Generator
NewCommentService(ctx *AppContext) ci.CommentService
}
GeneratorProvider supplies a pipeline generator and comment service for a CI provider.
func ResolveProvider ¶
func ResolveProvider() (GeneratorProvider, error)
ResolveProvider detects the active CI provider from registered GeneratorProviders. Priority: env detection → TERRACI_PROVIDER env → single registered → default gitlab fallback.
type InitContribution ¶
InitContribution holds the config produced by a plugin's init logic.
type InitContributor ¶
type InitContributor interface {
Plugin
InitGroup() *InitGroupSpec
BuildInitConfig(state InitState) *InitContribution
}
InitContributor plugins contribute fields and config to the init wizard.
type InitField ¶
type InitField struct {
Key string
Title string
Description string
Type string // "string", "bool", "select"
Default any
Options []InitOption
Placeholder string
}
InitField describes a single form field in the init wizard.
type InitGroupSpec ¶
type InitGroupSpec struct {
Title string
Order int
Fields []InitField
ShowWhen func(InitState) bool
}
InitGroupSpec describes a group of form fields contributed by a plugin.
type InitOption ¶
InitOption represents a selectable option for a field.
type InitState ¶
type InitState interface {
Get(key string) any
Set(key string, val any)
Provider() string
Binary() string
}
InitState provides read/write access to the shared init wizard state.
type Initializable ¶
type Initializable interface {
Plugin
Initialize(ctx context.Context, appCtx *AppContext) error
}
Initializable plugins set up resources after config is loaded, before any command runs.
type PipelineContributor ¶
type PipelineContributor interface {
Plugin
PipelineContribution() *pipeline.Contribution
}
PipelineContributor plugins add steps or jobs to the generated CI pipeline.
type Plugin ¶
type Plugin interface {
// Name returns a unique identifier (e.g., "gitlab", "cost", "slack").
Name() string
// Description returns a human-readable description.
Description() string
}
Plugin is the core interface every plugin must implement.
type StateMap ¶
type StateMap struct {
// contains filtered or unexported fields
}
StateMap is the default InitState implementation backed by maps. It provides stable pointers for huh form field binding.
func (*StateMap) BoolPtr ¶
BoolPtr returns a stable *bool pointer for huh form binding. If a value was previously Set for the key, it initializes the pointer with that value.
func (*StateMap) Get ¶
Get retrieves a value, preferring pointer-backed values from StringPtr/BoolPtr.
type SummaryContributor ¶
type SummaryContributor interface {
Plugin
ContributeToSummary(ctx context.Context, appCtx *AppContext, execCtx *ExecutionContext) error
}
SummaryContributor plugins enrich plan results during `terraci summary`. Called in registration order before comment rendering.
type VersionProvider ¶
VersionProvider plugins contribute version info to `terraci version`.