Help us shape the future of Go! Take the 2026 Go Developer Survey

hooks

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OnErrorFail = "fail"
	OnErrorWarn = "warn"
)
View Source
const RepoHooksPath = ".workset/hooks.yaml"

Variables

This section is empty.

Functions

func RepoHooksFile

func RepoHooksFile(repoPath string) string

Types

type Context

type Context struct {
	WorkspaceRoot   string
	WorkspaceName   string
	WorkspaceConfig string
	RepoName        string
	RepoDir         string
	RepoPath        string
	WorktreePath    string
	Branch          string
	Event           Event
	Reason          string
}

func (Context) Env

func (c Context) Env() []string

func (Context) TokenMap

func (c Context) TokenMap() map[string]string

type Engine

type Engine struct {
	Runner Runner
	Clock  func() time.Time
}

func (Engine) Run

func (e Engine) Run(ctx context.Context, input RunInput) (RunReport, error)

type Event

type Event string
const (
	EventWorktreeCreated Event = "worktree.created"
)

type ExecRunner

type ExecRunner struct{}

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, req RunRequest) error

type File

type File struct {
	Hooks []Hook `yaml:"hooks" json:"hooks"`
}

func LoadRepoHooks

func LoadRepoHooks(repoPath string) (File, bool, error)

func ParseRepoHooks

func ParseRepoHooks(data []byte) (File, error)

type Hook

type Hook struct {
	ID      string            `yaml:"id" json:"id"`
	On      []Event           `yaml:"on" json:"on"`
	Run     []string          `yaml:"run" json:"run"`
	Cwd     string            `yaml:"cwd,omitempty" json:"cwd,omitempty"`
	Env     map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
	OnError string            `yaml:"on_error,omitempty" json:"on_error,omitempty"`
}

type HookFailedError

type HookFailedError struct {
	HookID  string
	LogPath string
	Err     error
}

func (HookFailedError) Error

func (e HookFailedError) Error() string

type HookPhase

type HookPhase string
const (
	HookPhaseStarted  HookPhase = "started"
	HookPhaseFinished HookPhase = "finished"
)

type HookProgress

type HookProgress struct {
	Phase         HookPhase
	Event         Event
	HookID        string
	WorkspaceName string
	RepoName      string
	WorktreePath  string
	Reason        string
	Status        RunStatus
	LogPath       string
	Err           error
}

HookProgress reports hook execution lifecycle updates.

type RunInput

type RunInput struct {
	Event          Event
	Hooks          []Hook
	DefaultOnError string
	LogRoot        string
	Context        Context
	Observer       RunObserver
}

type RunObserver

type RunObserver interface {
	OnHookProgress(progress HookProgress)
}

RunObserver can receive live hook progress events.

type RunReport

type RunReport struct {
	Event   Event
	Results []RunResult
}

type RunRequest

type RunRequest struct {
	Command []string
	Cwd     string
	Env     []string
	Stdout  io.Writer
	Stderr  io.Writer
}

type RunResult

type RunResult struct {
	HookID  string
	Status  RunStatus
	LogPath string
	Err     error
}

type RunStatus

type RunStatus string
const (
	RunStatusOK      RunStatus = "ok"
	RunStatusFailed  RunStatus = "failed"
	RunStatusSkipped RunStatus = "skipped"
)

type Runner

type Runner interface {
	Run(ctx context.Context, req RunRequest) error
}

Jump to

Keyboard shortcuts

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