hooks

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hooks provides Git hooks management for visionspec.

This package enables automatic validation of specs on git operations: - pre-commit: Lint changed spec files - pre-push: Evaluate specs and check for blockers - commit-msg: Validate commit message references spec

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindRepoRoot

func FindRepoRoot(startPath string) (string, error)

FindRepoRoot finds the root of the git repository.

func GenerateCustomHook

func GenerateCustomHook(custom CustomTemplate) string

GenerateCustomHook generates a hook script from a custom template.

func GetTemplate

func GetTemplate(hookType HookType) string

GetTemplate returns the script template for a hook type.

func GetTemplateDescription

func GetTemplateDescription(hookType HookType) string

GetTemplateDescription returns a description of what a hook does.

Types

type Config

type Config struct {
	Enabled  bool              `json:"enabled" yaml:"enabled"`
	HooksDir string            `json:"hooks_dir,omitempty" yaml:"hooks_dir,omitempty"`
	Hooks    map[HookType]Hook `json:"hooks,omitempty" yaml:"hooks,omitempty"`
}

Config holds hooks configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default hooks configuration.

type CustomTemplate

type CustomTemplate struct {
	HookType    HookType
	Description string
	Script      string
}

CustomTemplate allows creating a custom hook template.

type Hook

type Hook struct {
	Type        HookType `json:"type" yaml:"type"`
	Enabled     bool     `json:"enabled" yaml:"enabled"`
	Description string   `json:"description" yaml:"description"`
	Script      string   `json:"script" yaml:"script"`
}

Hook represents a Git hook configuration.

type HookStatus

type HookStatus struct {
	Type         HookType `json:"type"`
	Installed    bool     `json:"installed"`
	IsVisionSpec bool     `json:"is_visionspec"`
	Executable   bool     `json:"executable"`
	Error        string   `json:"error,omitempty"`
}

HookStatus contains the status of a single hook.

type HookType

type HookType string

HookType represents a Git hook type.

const (
	HookPreCommit  HookType = "pre-commit"
	HookPrePush    HookType = "pre-push"
	HookCommitMsg  HookType = "commit-msg"
	HookPostCommit HookType = "post-commit"
)

func AllHookTypes

func AllHookTypes() []HookType

AllHookTypes returns all supported hook types.

type InstallResult

type InstallResult struct {
	HooksDir  string   `json:"hooks_dir"`
	Installed []string `json:"installed"`
	BackedUp  []string `json:"backed_up,omitempty"`
	Errors    []string `json:"errors,omitempty"`
}

InstallResult contains the result of installing hooks.

type Manager

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

Manager handles Git hooks operations.

func NewManager

func NewManager(repoRoot string, config Config) *Manager

NewManager creates a new hooks manager.

func (*Manager) GitHooksDir

func (m *Manager) GitHooksDir() (string, error)

GitHooksDir returns the path to the .git/hooks directory.

func (*Manager) Install

func (m *Manager) Install(hookTypes []HookType) (*InstallResult, error)

Install installs visionspec Git hooks.

func (*Manager) Status

func (m *Manager) Status() (*StatusResult, error)

Status checks the status of installed hooks.

func (*Manager) Uninstall

func (m *Manager) Uninstall(hookTypes []HookType) (*UninstallResult, error)

Uninstall removes visionspec Git hooks.

type StatusResult

type StatusResult struct {
	HooksDir string                  `json:"hooks_dir"`
	Hooks    map[HookType]HookStatus `json:"hooks"`
}

StatusResult contains the status of hooks.

type UninstallResult

type UninstallResult struct {
	HooksDir string   `json:"hooks_dir"`
	Removed  []string `json:"removed"`
	Restored []string `json:"restored,omitempty"`
	Skipped  []string `json:"skipped,omitempty"`
	Errors   []string `json:"errors,omitempty"`
}

UninstallResult contains the result of uninstalling hooks.

Jump to

Keyboard shortcuts

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