plugins

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package plugins provides a plugin system for custom pre-commit hooks

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrManifestNil     = errors.New("manifest cannot be nil")
	ErrPluginNameEmpty = errors.New("plugin name is required")
	ErrExecutableEmpty = errors.New("plugin executable is required")
)

Define plugin errors

View Source
var (
	ErrPluginAlreadyRegistered = errors.New("plugin already registered")
	ErrPluginNil               = errors.New("plugin cannot be nil")
	ErrNoManifestFound         = errors.New("no manifest file found (looked for plugin.yaml, plugin.yml, plugin.json)")
	ErrPluginsLoadFailed       = errors.New("failed to load some plugins")
)

Define registry errors

Functions

func ValidateManifest

func ValidateManifest(manifest *PluginManifest) []string

ValidateManifest validates a plugin manifest without loading it

Types

type Plugin

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

Plugin represents a custom check implemented as an external executable

func NewPlugin

func NewPlugin(manifest *PluginManifest, directory string) (*Plugin, error)

NewPlugin creates a new plugin from a manifest and directory

func (*Plugin) Description

func (p *Plugin) Description() string

Description returns a brief description of the plugin

func (*Plugin) FilterFiles

func (p *Plugin) FilterFiles(files []string) []string

FilterFiles filters the list of files to only those this plugin should process

func (*Plugin) Metadata

func (p *Plugin) Metadata() interface{}

Metadata returns comprehensive metadata about the plugin

func (*Plugin) Name

func (p *Plugin) Name() string

Name returns the name of the plugin

func (*Plugin) Run

func (p *Plugin) Run(ctx context.Context, files []string) error

Run executes the plugin on the given files

type PluginManifest

type PluginManifest struct {
	// Basic metadata
	Name        string `json:"name" yaml:"name"`
	Version     string `json:"version" yaml:"version"`
	Description string `json:"description" yaml:"description"`
	Author      string `json:"author,omitempty" yaml:"author,omitempty"`
	License     string `json:"license,omitempty" yaml:"license,omitempty"`
	Homepage    string `json:"homepage,omitempty" yaml:"homepage,omitempty"`

	// Execution configuration
	Executable    string            `json:"executable" yaml:"executable"`
	Args          []string          `json:"args,omitempty" yaml:"args,omitempty"`
	FilePatterns  []string          `json:"file_patterns" yaml:"file_patterns"`
	Timeout       string            `json:"timeout,omitempty" yaml:"timeout,omitempty"`
	Category      string            `json:"category,omitempty" yaml:"category,omitempty"`
	RequiresFiles bool              `json:"requires_files,omitempty" yaml:"requires_files,omitempty"`
	Environment   map[string]string `json:"environment,omitempty" yaml:"environment,omitempty"`

	// Advanced configuration
	Dependencies []string `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
	MinVersion   string   `json:"min_go_pre_commit_version,omitempty" yaml:"min_go_pre_commit_version,omitempty"`
	MaxVersion   string   `json:"max_go_pre_commit_version,omitempty" yaml:"max_go_pre_commit_version,omitempty"`

	// Security settings
	ReadOnly      bool     `json:"read_only,omitempty" yaml:"read_only,omitempty"`
	AllowedPaths  []string `json:"allowed_paths,omitempty" yaml:"allowed_paths,omitempty"`
	MaxMemoryMB   int      `json:"max_memory_mb,omitempty" yaml:"max_memory_mb,omitempty"`
	MaxCPUPercent int      `json:"max_cpu_percent,omitempty" yaml:"max_cpu_percent,omitempty"`
}

PluginManifest defines the structure of a plugin configuration file

type PluginMetadata

type PluginMetadata struct {
	Name              string
	Description       string
	FilePatterns      []string
	EstimatedDuration time.Duration
	Dependencies      []string
	DefaultTimeout    time.Duration
	Category          string
	RequiresFiles     bool
	Version           string
	Author            string
}

PluginMetadata contains metadata about a plugin

type PluginRequest

type PluginRequest struct {
	Command string            `json:"command"`
	Files   []string          `json:"files"`
	Config  map[string]string `json:"config,omitempty"`
}

PluginRequest is the JSON structure sent to plugins via stdin

type PluginResponse

type PluginResponse struct {
	Success    bool     `json:"success"`
	Error      string   `json:"error,omitempty"`
	Suggestion string   `json:"suggestion,omitempty"`
	Modified   []string `json:"modified,omitempty"`
	Output     string   `json:"output,omitempty"`
}

PluginResponse is the JSON structure expected from plugins via stdout

type Registry

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

Registry manages plugin discovery and loading

func NewRegistry

func NewRegistry(directory string) *Registry

NewRegistry creates a new plugin registry

func (*Registry) AddPlugin

func (r *Registry) AddPlugin(plugin *Plugin) error

AddPlugin manually adds a plugin to the registry

func (*Registry) Get

func (r *Registry) Get(name string) (*Plugin, bool)

Get returns a plugin by name

func (*Registry) GetAll

func (r *Registry) GetAll() []*Plugin

GetAll returns all loaded plugins

func (*Registry) LoadPlugins

func (r *Registry) LoadPlugins() error

LoadPlugins discovers and loads all plugins from the registry directory

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the names of all loaded plugins

func (*Registry) RemovePlugin

func (r *Registry) RemovePlugin(name string) bool

RemovePlugin removes a plugin from the registry

Jump to

Keyboard shortcuts

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