expr

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package expr provides expression evaluation for pipeline gates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(expression string) error

Compile validates an expression at config load time. Returns an error if the expression is invalid.

func CompileWithContext

func CompileWithContext(expression string, ctx Context) error

CompileWithContext validates an expression with a specific context.

func Evaluate

func Evaluate(expression string, ctx Context) (bool, error)

Evaluate compiles and runs an expression against the context. Returns true if the expression evaluates to true, false otherwise.

Types

type ACContext

type ACContext struct {
	Items ItemsContext `expr:"items"`
}

ACContext contains acceptance criteria statistics.

type AlertsContext

type AlertsContext struct {
	Count    int `expr:"count"`
	Critical int `expr:"critical"`
	Warning  int `expr:"warning"`
}

AlertsContext contains alert statistics.

type Context

type Context struct {
	// Spec contains spec metadata
	Spec SpecContext `expr:"spec"`

	// Sections contains per-section metadata keyed by slug
	Sections map[string]SectionContext `expr:"sections"`

	// Decisions contains decision log statistics
	Decisions DecisionsContext `expr:"decisions"`

	// AcceptanceCriteria contains AC statistics
	AcceptanceCriteria ACContext `expr:"acceptance_criteria"`

	// PRStack contains PR stack plan statistics
	PRStack PRStackContext `expr:"pr_stack"`

	// PRs contains pull request statistics
	PRs PRsContext `expr:"prs"`

	// Deploy contains deployment status
	Deploy DeployContext `expr:"deploy"`

	// Alerts contains alert statistics
	Alerts AlertsContext `expr:"alerts"`
}

Context is the environment available to gate expressions. All fields are exported and accessible in expressions.

func NewContext

func NewContext() Context

NewContext creates a new empty context with initialized maps.

type ContextBuilder

type ContextBuilder struct {
	// contains filtered or unexported fields
}

ContextBuilder helps build an expression context from spec data.

func NewContextBuilder

func NewContextBuilder() *ContextBuilder

NewContextBuilder creates a new context builder.

func (*ContextBuilder) Build

func (b *ContextBuilder) Build() Context

Build returns the built context.

func (*ContextBuilder) WithAcceptanceCriteria

func (b *ContextBuilder) WithAcceptanceCriteria(count, checked int) *ContextBuilder

WithAcceptanceCriteria sets AC statistics.

func (*ContextBuilder) WithAlerts

func (b *ContextBuilder) WithAlerts(count, critical, warning int) *ContextBuilder

WithAlerts sets alert statistics.

func (*ContextBuilder) WithDecisions

func (b *ContextBuilder) WithDecisions(total, resolved int) *ContextBuilder

WithDecisions sets decision log statistics.

func (*ContextBuilder) WithDeploy

func (b *ContextBuilder) WithDeploy(stagingStatus string, stagingHealthy bool, prodStatus string, prodHealthy bool) *ContextBuilder

WithDeploy sets deployment status.

func (*ContextBuilder) WithPRStack

func (b *ContextBuilder) WithPRStack(exists bool, steps, completed int, allOpened, allApproved bool) *ContextBuilder

WithPRStack sets PR stack statistics.

func (*ContextBuilder) WithPRs

func (b *ContextBuilder) WithPRs(open, approved int, threadsResolved bool) *ContextBuilder

WithPRs sets pull request statistics.

func (*ContextBuilder) WithSection

func (b *ContextBuilder) WithSection(slug string, content string) *ContextBuilder

WithSection adds a section to the context.

func (*ContextBuilder) WithSections

func (b *ContextBuilder) WithSections(sections map[string]string) *ContextBuilder

WithSections adds multiple sections to the context.

func (*ContextBuilder) WithSpec

func (b *ContextBuilder) WithSpec(id, title, status string, labels []string, wordCount int, timeInStage time.Duration, revertCount int) *ContextBuilder

WithSpec sets spec metadata.

type DecisionsContext

type DecisionsContext struct {
	Total      int `expr:"total"`
	Resolved   int `expr:"resolved"`
	Unresolved int `expr:"unresolved"`
}

DecisionsContext contains decision log statistics.

type DeployContext

type DeployContext struct {
	Staging    EnvironmentStatus `expr:"staging"`
	Production EnvironmentStatus `expr:"production"`
}

DeployContext contains deployment status.

type EnvironmentStatus

type EnvironmentStatus struct {
	Status  string `expr:"status"` // pending, running, success, failed
	Healthy bool   `expr:"healthy"`
}

EnvironmentStatus contains status for a deployment environment.

type ItemsContext

type ItemsContext struct {
	Count     int `expr:"count"`
	Checked   int `expr:"checked"`
	Unchecked int `expr:"unchecked"`
}

ItemsContext contains item count information.

type PRStackContext

type PRStackContext struct {
	Exists      bool `expr:"exists"`
	Steps       int  `expr:"steps"`
	Completed   int  `expr:"completed"`
	Pending     int  `expr:"pending"`
	AllOpened   bool `expr:"all_opened"`
	AllApproved bool `expr:"all_approved"`
}

PRStackContext contains PR stack plan statistics.

type PRsContext

type PRsContext struct {
	Open            int  `expr:"open"`
	Approved        int  `expr:"approved"`
	Pending         int  `expr:"pending"`
	ThreadsResolved bool `expr:"threads_resolved"`
}

PRsContext contains pull request statistics.

type SectionContext

type SectionContext struct {
	Empty     bool `expr:"empty"`
	WordCount int  `expr:"word_count"`
	LineCount int  `expr:"line_count"`
}

SectionContext contains metadata about a spec section.

type SpecContext

type SpecContext struct {
	ID          string        `expr:"id"`
	Title       string        `expr:"title"`
	Status      string        `expr:"status"`
	Labels      []string      `expr:"labels"`
	TimeInStage time.Duration `expr:"time_in_stage"`
	RevertCount int           `expr:"revert_count"`
	WordCount   int           `expr:"word_count"`
}

SpecContext contains spec metadata for expressions.

Jump to

Keyboard shortcuts

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