config

package
v0.0.0-...-e7367c0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigPath = ".gitte.yml"
View Source
const DotEnvPath = ".gitte-env"
View Source
const OverridePath = ".gitte-override.yml"

Variables

View Source
var ErrGitteConfigNotFound = errors.New("gitte configuration file not found")

Functions

func ContextWithConfig

func ContextWithConfig(ctx context.Context, cfg *GitteConfig) context.Context

ContextWithConfig stores the GitteConfig in context

func ContextWithCwd

func ContextWithCwd(ctx context.Context, cwd string) context.Context

ContextWithCwd stores the working directory in context

func CwdFromContext

func CwdFromContext(ctx context.Context) string

CwdFromContext retrieves the working directory from context

func LoadRemoteConfig

func LoadRemoteConfig(ctx context.Context, envContent []byte, cache *RemoteConfigCache, onRefreshed func(*RemoteConfigCache), verbose bool) (*GitteConfig, *RemoteConfigCache, error)

LoadRemoteConfig fetches remote config via git archive. If a valid cache entry exists it is returned immediately and a background goroutine is started to refresh the cache. onRefreshed is called with the new cache entry when the refresh completes (use it to persist the cache).

func LocalDirForRemote

func LocalDirForRemote(remote string) (string, error)

LocalDirForRemote returns the local directory path for a project's remote URL

func MarshalYAMLRemoteCache

func MarshalYAMLRemoteCache(cache *RemoteConfigCache) ([]byte, error)

MarshalYAMLRemoteCache serializes cache to YAML bytes.

func ParseRemoteURL

func ParseRemoteURL(remote string) (host, path, localDir string, err error)

ParseRemoteURL parses a git remote URL and returns (host, namespacedPath, localDir) Supports:

git@gitlab.example.com:org/services/myrepo.git  -> gitlab.example.com/org/services/myrepo
https://github.com/example/myrepo.git           -> github.com/example/myrepo

func ResolveEnvWhen

func ResolveEnvWhen(entries map[string]EnvWhenEntry, arch string) map[string]string

ResolveEnvWhen evaluates env_when entries against the given arch and returns only the variables whose conditions all pass. arch should be runtime.GOARCH. Unknown condition types conservatively exclude the variable.

func ResolveTemplates

func ResolveTemplates(cfg *GitteConfig) error

ResolveTemplates applies template inheritance (extends) to all projects and performs Go text/template variable substitution. It modifies cfg.Projects in place and removes cfg.Templates when done.

func SaveOverrideConfig

func SaveOverrideConfig(dir string, cfg *GitteConfig) error

SaveOverrideConfig writes cfg to .gitte-override.yml, replacing any existing file.

Types

type ActionOverride

type ActionOverride struct {
	MaxParallelization int `yaml:"maxParallelization,omitempty"`
}

ActionOverride allows per-action configuration overrides

type BaseStartupCheck

type BaseStartupCheck struct {
	Type  string   `yaml:"type"`
	Hint  string   `yaml:"hint,omitempty"`
	Needs []string `yaml:"needs,omitempty"`
}

BaseStartupCheck holds common fields for all check types

func (*BaseStartupCheck) GetHint

func (b *BaseStartupCheck) GetHint() string

func (*BaseStartupCheck) GetNeeds

func (b *BaseStartupCheck) GetNeeds() []string

func (*BaseStartupCheck) GetType

func (b *BaseStartupCheck) GetType() string

type CommandStartupCheck

type CommandStartupCheck struct {
	BaseStartupCheck `yaml:",inline"`
	Command          []string `yaml:"cmd"`
}

CommandStartupCheck runs a command and checks exit code

func (*CommandStartupCheck) Check

func (s *CommandStartupCheck) Check(ctx context.Context, cwd string, stdout, stderr io.Writer) error

type EnvWhenCondition

type EnvWhenCondition struct {
	Type string   `yaml:"type"`
	Arch []string `yaml:"arch,omitempty"`
}

EnvWhenCondition is one condition in an EnvWhenEntry. Type is the discriminator; currently only "arch" is supported.

type EnvWhenEntry

type EnvWhenEntry struct {
	Value      string             `yaml:"value"`
	Conditions []EnvWhenCondition `yaml:"conditions,omitempty"`
}

EnvWhenEntry is a single entry in an env_when map. The variable is only injected when all Conditions pass. An empty Conditions list means always inject (equivalent to plain env).

type FeatureEffects

type FeatureEffects struct {
	Env     map[string]string       `yaml:"env,omitempty"`
	EnvWhen map[string]EnvWhenEntry `yaml:"env_when,omitempty"`
}

FeatureEffects defines what a feature gate does when enabled

type FeatureGate

type FeatureGate struct {
	Description string         `yaml:"description,omitempty"`
	Effects     FeatureEffects `yaml:"effects,omitempty"`
	Scope       FeatureScope   `yaml:"scope,omitempty"`
}

FeatureGate defines a feature that can be enabled/disabled per machine

type FeatureScope

type FeatureScope struct {
	Projects     []string      `yaml:"projects,omitempty"`
	GitlabGroups []GitlabScope `yaml:"gitlab_groups,omitempty"`
	GithubOrgs   []GithubScope `yaml:"github_orgs,omitempty"`
}

FeatureScope defines which projects a feature gate applies to

type FileDefinition

type FileDefinition struct {
	ConfigContent []byte
	IsEnv         bool
	Directory     string
}

FileDefinition holds raw config file content and metadata

func ResolveGitteDir

func ResolveGitteDir(cwd string) (FileDefinition, error)

ResolveGitteDir walks up from cwd to find .gitte.yml or .gitte-env

type GithubScope

type GithubScope struct {
	Host string `yaml:"host"`
	Org  string `yaml:"org"`
}

GithubScope defines a GitHub org scope for feature gates

type GithubSource

type GithubSource struct {
	Host     string   `yaml:"host"`
	TokenEnv string   `yaml:"token_env,omitempty"`
	TokenCmd string   `yaml:"token_cmd,omitempty"`
	Orgs     []string `yaml:"orgs,omitempty"`
}

GithubSource defines a GitHub source for auto-discovery

type GitlabScope

type GitlabScope struct {
	Host  string `yaml:"host"`
	Group string `yaml:"group"`
}

GitlabScope defines a GitLab group scope for feature gates

type GitlabSource

type GitlabSource struct {
	Host     string   `yaml:"host"`
	TokenEnv string   `yaml:"token_env,omitempty"`
	TokenCmd string   `yaml:"token_cmd,omitempty"`
	Groups   []string `yaml:"groups,omitempty"`
}

GitlabSource defines a GitLab source for auto-discovery

type GitteConfig

type GitteConfig struct {
	StartupChecks  StartupCheckMap           `yaml:"startup,omitempty"`
	Templates      map[string]Template       `yaml:"templates,omitempty"`
	FeatureGates   map[string]FeatureGate    `yaml:"feature_gates,omitempty"`
	Sources        Sources                   `yaml:"sources,omitempty"`
	SearchFor      []SearchFor               `yaml:"searchFor,omitempty"`
	ActionOverride map[string]ActionOverride `yaml:"actionOverride,omitempty"`
	Retry          RetryDefaults             `yaml:"retry,omitempty"`
	GroupIncludes  map[string][]string       `yaml:"groupIncludes,omitempty"`
	Projects       map[string]ProjectConfig  `yaml:"projects,omitempty"`
	QuickSolve     QuickSolveConfig          `yaml:"quickSolve,omitempty"`
	Telemetry      TelemetryConfig           `yaml:"telemetry,omitempty"`
}

GitteConfig is the top-level configuration struct for .gitte.yml

func ConfigFromContext

func ConfigFromContext(ctx context.Context) *GitteConfig

ConfigFromContext retrieves the GitteConfig from context

func LoadAndMergeConfig

func LoadAndMergeConfig(fd FileDefinition) (*GitteConfig, error)

LoadAndMergeConfig loads .gitte.yml and merges .gitte-override.yml if present

func LoadGitteConfigFromYAML

func LoadGitteConfigFromYAML(content []byte) (*GitteConfig, error)

LoadGitteConfigFromYAML parses raw YAML bytes into a GitteConfig

func LoadOverrideConfig

func LoadOverrideConfig(dir string) (*GitteConfig, error)

LoadOverrideConfig loads .gitte-override.yml and returns it as a GitteConfig. Returns an empty config if the file does not exist.

func MergeOverride

func MergeOverride(base, override *GitteConfig) *GitteConfig

MergeOverride merges an override config on top of the base config Override values win over base values (shallow at top level, deep for projects/actions).

func (*GitteConfig) FilterToggles

func (cfg *GitteConfig) FilterToggles(toggledProjects ToggledProjects)

FilterToggles removes projects based on toggle state

func (*GitteConfig) WithTogglesApplied

func (cfg *GitteConfig) WithTogglesApplied(toggledProjects ToggledProjects) *GitteConfig

WithTogglesApplied returns a shallow copy of the config with toggles applied, leaving the receiver unmodified. Used by the toggle command which needs the full (unfiltered) project list.

type ProjectAction

type ProjectAction struct {
	SearchFors []SearchFor         `yaml:"searchFor,omitempty"`
	Needs      []string            `yaml:"needs,omitempty"`
	Groups     map[string][]string `yaml:"groups,omitempty"`
	Retry      *RetryConfig        `yaml:"retry,omitempty"`
}

ProjectAction represents an action (build/up/down/purge) for a project

type ProjectConfig

type ProjectConfig struct {
	Remote          string                   `yaml:"remote"`
	DefaultBranch   string                   `yaml:"default_branch,omitempty"`
	Actions         map[string]ProjectAction `yaml:"actions,omitempty"`
	DefaultDisabled bool                     `yaml:"defaultDisabled,omitempty"`
	Extends         string                   `yaml:"extends,omitempty"`
	Vars            map[string]string        `yaml:"vars,omitempty"`
	Env             map[string]string        `yaml:"env,omitempty"`
	EnvWhen         map[string]EnvWhenEntry  `yaml:"env_when,omitempty"`
}

ProjectConfig represents a single project in the config

type QuickSolveConfig

type QuickSolveConfig struct {
	GitClean QuickSolveGitClean `yaml:"git_clean,omitempty"`
}

QuickSolveConfig holds settings for the quick solve feature in the actions TUI.

type QuickSolveGitClean

type QuickSolveGitClean struct {
	Exclude []string `yaml:"exclude,omitempty"`
}

QuickSolveGitClean configures which directories are excluded from git clean -fdx.

type RemoteConfigCache

type RemoteConfigCache struct {
	RemoteGitRepo string    `yaml:"remote_git_repo"`
	RemoteGitFile string    `yaml:"remote_git_file"`
	RemoteGitRef  string    `yaml:"remote_git_ref"`
	FetchedAt     time.Time `yaml:"fetched_at"`
	Content       string    `yaml:"content"`
}

RemoteConfigCache holds cached remote config state

type RetryConfig

type RetryConfig struct {
	Attempts int    `yaml:"attempts"`
	Delay    string `yaml:"delay,omitempty"`   // e.g. "5s", "10s"
	Backoff  string `yaml:"backoff,omitempty"` // "none", "linear", "exponential"
}

RetryConfig defines retry behavior for a task

type RetryDefaults

type RetryDefaults struct {
	Default RetryConfig `yaml:"default,omitempty"`
}

RetryDefaults holds global retry defaults

type SearchFor

type SearchFor struct {
	Regex string `yaml:"regex"`
	Hint  string `yaml:"hint"`
}

SearchFor defines a regex pattern and hint for output matching

type ShellStartupCheck

type ShellStartupCheck struct {
	BaseStartupCheck `yaml:",inline"`
	Shell            string `yaml:"shell"`
	Script           string `yaml:"script"`
}

ShellStartupCheck runs a shell script

func (*ShellStartupCheck) Check

func (s *ShellStartupCheck) Check(ctx context.Context, cwd string, stdout, stderr io.Writer) error

type Sources

type Sources struct {
	Gitlab []GitlabSource `yaml:"gitlab,omitempty"`
	Github []GithubSource `yaml:"github,omitempty"`
}

Sources defines auto-discovery sources

type StartupCheck

type StartupCheck interface {
	GetType() string
	GetHint() string
	GetNeeds() []string
	Check(ctx context.Context, cwd string, stdout, stderr io.Writer) error
}

StartupCheck is the interface for all startup check types

type StartupCheckMap

type StartupCheckMap map[string]StartupCheck

StartupCheckMap is a map of startup checks with custom YAML unmarshaling

func (*StartupCheckMap) UnmarshalYAML

func (cm *StartupCheckMap) UnmarshalYAML(value *yaml.Node) error

type TelemetryConfig

type TelemetryConfig struct {
	Endpoint string            `yaml:"endpoint,omitempty"`
	Headers  map[string]string `yaml:"headers,omitempty"`
}

TelemetryConfig configures OpenTelemetry tracing export. Telemetry is enabled when an endpoint is resolved (from this config or the GITTE_TELEMETRY_URL env var). Headers carries arbitrary export headers, e.g. an Elastic APM secret token as Authorization: "Bearer <token>" or an API key as "ApiKey <key>".

type Template

type Template struct {
	Extends []string                 `yaml:"extends,omitempty"`
	Vars    map[string]string        `yaml:"vars,omitempty"`
	Env     map[string]string        `yaml:"env,omitempty"`
	EnvWhen map[string]EnvWhenEntry  `yaml:"env_when,omitempty"`
	Actions map[string]ProjectAction `yaml:"actions,omitempty"`
}

Template is a reusable project configuration template. Extends lists parent template names (resolved left-to-right, self applied last).

type ToggledProjects

type ToggledProjects = map[string]bool

ToggledProjects maps project keys to their explicit enabled/disabled state

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError represents a single config validation issue

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationResult

type ValidationResult struct {
	Errors   []ValidationError
	Warnings []ValidationError
}

ValidationResult holds all errors and warnings from validation

func ValidateConfig

func ValidateConfig(cfg *GitteConfig) *ValidationResult

ValidateConfig performs structural validation on the config

func (*ValidationResult) AddError

func (r *ValidationResult) AddError(field, msg string)

func (*ValidationResult) AddWarning

func (r *ValidationResult) AddWarning(field, msg string)

func (*ValidationResult) HasErrors

func (r *ValidationResult) HasErrors() bool

type YamlPathPresentStartupCheck

type YamlPathPresentStartupCheck struct {
	BaseStartupCheck `yaml:",inline"`
	Path             string `yaml:"path"`
	File             string `yaml:"file"`
}

YamlPathPresentStartupCheck checks that a YAML path exists in a file

func (*YamlPathPresentStartupCheck) Check

Jump to

Keyboard shortcuts

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