plugin

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 10 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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.

func Register

func Register(p Plugin)

Register adds a plugin to the global registry. Called from init() in plugin packages. Panics on duplicate names (fail-fast at startup).

func Reset

func Reset()

Reset clears the registry. Only for testing.

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

type InitContribution struct {
	PluginKey string
	Config    map[string]any
}

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

type InitOption struct {
	Label string
	Value string
}

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.

func All

func All() []Plugin

All returns registered plugins in registration order.

func Get

func Get(name string) (Plugin, bool)

Get returns a plugin by name.

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 NewStateMap

func NewStateMap() *StateMap

NewStateMap creates a new empty StateMap.

func (*StateMap) Binary

func (s *StateMap) Binary() string

Binary returns the current binary name.

func (*StateMap) BoolPtr

func (s *StateMap) BoolPtr(key string) *bool

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

func (s *StateMap) Get(key string) any

Get retrieves a value, preferring pointer-backed values from StringPtr/BoolPtr.

func (*StateMap) Provider

func (s *StateMap) Provider() string

Provider returns the current provider name.

func (*StateMap) Set

func (s *StateMap) Set(key string, val any)

Set stores a value in the state.

func (*StateMap) StringPtr

func (s *StateMap) StringPtr(key string) *string

StringPtr returns a stable *string pointer for huh form binding. If a value was previously Set for the key, it initializes the pointer with that value.

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

type VersionProvider interface {
	Plugin
	VersionInfo() map[string]string
}

VersionProvider plugins contribute version info to `terraci version`.

Jump to

Keyboard shortcuts

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