expr

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 3 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 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) 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) 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