Documentation
¶
Overview ¶
Package hooks manages declarative, user-owned Git hook templates.
Index ¶
- Constants
- func AppendEvent(path string, event Event) error
- func RepositoryRoot(path string) (string, error)
- type ApplyOptions
- type ApplyResult
- type CheckReport
- type DailyMetrics
- type Event
- type Finding
- type HookConfig
- type MetricsConfig
- type MetricsPolicy
- type MetricsSummary
- type Policy
- type ResolvedHook
- type RunOptions
- type RunResult
Constants ¶
const ( BuiltinPreCommit = "builtin:pre-commit" BuiltinPrePush = "builtin:pre-push" )
const EventSchemaVersion = 1
const PolicyVersion = 1
Variables ¶
This section is empty.
Functions ¶
func AppendEvent ¶
func RepositoryRoot ¶
RepositoryRoot resolves path to the enclosing non-bare Git worktree.
Types ¶
type ApplyOptions ¶
type ApplyResult ¶
type ApplyResult struct {
Report CheckReport
Actions []string
}
func Apply ¶
func Apply(options ApplyOptions) (ApplyResult, error)
Apply installs or repairs WB's local shims. It never overwrites unmanaged hook files unless Force is set, and forced replacements are backed up.
type CheckReport ¶
type CheckReport struct {
RepoRoot string `json:"repo_root"`
ManagedPath string `json:"managed_path"`
ConfigPaths []string `json:"config_paths,omitempty"`
Hooks []string `json:"hooks"`
MetricsPath string `json:"metrics_path,omitempty"`
Findings []Finding `json:"findings,omitempty"`
}
func Check ¶
func Check(repoPath, configPath, wbExecutable string) (CheckReport, error)
Check validates config, core.hooksPath, generated shims, and executability without changing repository state.
type DailyMetrics ¶
type DailyMetrics struct {
Date string `json:"date"`
Commits int `json:"commits"`
PushAttempts int `json:"push_attempts"`
CommitChecks int `json:"commit_checks"`
HookFailures int `json:"hook_failures"`
HookRuns int `json:"hook_runs"`
TotalDurationMS int64 `json:"total_duration_ms"`
AverageDurationMS int64 `json:"average_duration_ms"`
}
type Event ¶
type Event struct {
SchemaVersion int `json:"schema_version"`
Timestamp time.Time `json:"timestamp"`
Repository string `json:"repository"`
Hook string `json:"hook"`
Action string `json:"action"`
Outcome string `json:"outcome"`
DurationMS int64 `json:"duration_ms"`
Commit string `json:"commit,omitempty"`
Branch string `json:"branch,omitempty"`
OS string `json:"os"`
Arch string `json:"arch"`
Labels map[string]string `json:"labels,omitempty"`
}
func ReadEvents ¶
type HookConfig ¶
type HookConfig struct {
Template string `yaml:"template" json:"template,omitempty"`
Disabled bool `yaml:"disabled" json:"disabled,omitempty"`
}
HookConfig selects a script template for one Git hook. Relative template paths are resolved from the YAML file that declares them.
type MetricsConfig ¶
type MetricsConfig struct {
Enabled *bool `yaml:"enabled" json:"enabled,omitempty"`
Path string `yaml:"path" json:"path,omitempty"`
Labels map[string]string `yaml:"labels" json:"labels,omitempty"`
}
MetricsConfig controls local hook-event collection. Enabled is a pointer so a repository policy can explicitly override a global true/false value.
type MetricsPolicy ¶
type MetricsSummary ¶
type MetricsSummary struct {
From string `json:"from"`
Through string `json:"through"`
RepositoryFilter string `json:"repository_filter,omitempty"`
Commits int `json:"commits"`
PushAttempts int `json:"push_attempts"`
CommitChecks int `json:"commit_checks"`
HookFailures int `json:"hook_failures"`
HookRuns int `json:"hook_runs"`
AverageDurationMS int64 `json:"average_duration_ms"`
Days []DailyMetrics `json:"days"`
}
type Policy ¶
type Policy struct {
RepoRoot string
ConfigPaths []string
Hooks map[string]ResolvedHook
Metrics MetricsPolicy
ExplicitPath string
}
Policy is the effective configuration after built-ins, the user's global policy, and the repository policy have been layered in that order.
func LoadPolicy ¶
LoadPolicy loads ~/.config/wb/hooks.yaml and .wb/hooks.yaml when present. An explicit path replaces those discovery locations but still layers on top of WB's conservative built-in templates.
type ResolvedHook ¶
type ResolvedHook struct {
Name string
Template string
Builtin bool
Disabled bool
ConfigPath string
}
ResolvedHook is a validated hook entry ready to execute.
type RunOptions ¶
type RunResult ¶
func Run ¶
func Run(options RunOptions) (RunResult, error)
Run executes a configured template in the repository root and records a compact local event. Hook script stdin/stdout/stderr and arguments are passed through unchanged so pre-push and commit-message hooks keep Git semantics.