validator

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigName = ".commitlint-scope"

Variables

View Source
var (
	ErrGetMessage      = errors.New("get commit message")
	ErrGetChangedFiles = errors.New("get changed files")
	ErrShaLength       = errors.New("sha length must be greater than 0")
)
View Source
var ErrConfigRead = errors.New("error reading config")
View Source
var ErrInvalidGlobPattern = errors.New("invalid glob pattern")
View Source
var ErrRegexDecode = errors.New("expected string for regexp decode")

Functions

This section is empty.

Types

type Config

type Config struct {
	ScopeRegex *regexp.Regexp      `mapstructure:"scopeRegex"`
	Patterns   map[string][]string `mapstructure:"patterns"`
}

func LoadConfig

func LoadConfig() (Config, error)

type DefaultGit

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

func NewDefaultGit

func NewDefaultGit(baseDir string) *DefaultGit

func (*DefaultGit) FilesChanged

func (d *DefaultGit) FilesChanged(ctx context.Context, sha string) ([]string, error)

func (*DefaultGit) Message

func (d *DefaultGit) Message(ctx context.Context, sha string) (string, error)

func (*DefaultGit) SHA

func (d *DefaultGit) SHA(ctx context.Context, from, to string) ([]string, error)

type DefaultOutsiderFinder

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

DefaultOutsiderFinder checks whether files match predefined glob patterns for a given scope.

func NewDefaultOutsiderFinder

func NewDefaultOutsiderFinder(scopesToPatterns map[string][]string) (*DefaultOutsiderFinder, error)

NewDefaultOutsiderFinder creates a new DefaultOutsiderFinder. scopesToPatterns is a map from scope name to a list of glob pattern strings.

func (*DefaultOutsiderFinder) Find

func (f *DefaultOutsiderFinder) Find(scope string, files []string) []Outsider

Find returns files that do not match any pattern for the given scope. If the scope has no patterns, zero config fallback applied - (scope + /**)

type DefaultScopeParser

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

func NewDefaultScopeParser

func NewDefaultScopeParser(scopeRegex *regexp.Regexp) *DefaultScopeParser

func (*DefaultScopeParser) Parse

func (p *DefaultScopeParser) Parse(message string) string

type Git

type Git interface {
	SHA(ctx context.Context, from, to string) ([]string, error)
	Message(ctx context.Context, sha string) (string, error)
	FilesChanged(ctx context.Context, sha string) ([]string, error)
}

type Options

type Options struct {
	Logger         *slog.Logger
	SHALength      int
	Git            Git
	OutsiderFinder OutsiderFinder
	ScopeParser    ScopeParser
}

type Outsider

type Outsider struct {
	File              string   `json:"file,omitempty"`
	UnmatchedPatterns []string `json:"unmatchedPatterns,omitempty"`
}

Outsider holds a file that failed the scope check and the patterns that were tested.

type OutsiderFinder

type OutsiderFinder interface {
	Find(scope string, files []string) []Outsider
}

type ScopeParser

type ScopeParser interface {
	Parse(message string) string
}

type Validator

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

func NewValidator

func NewValidator(cfg Config, options Options) (*Validator, error)

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, from, to string) ([]Violation, error)

type Violation

type Violation struct {
	SHA       string     `json:"sha"`
	Header    string     `json:"header"`
	Outsiders []Outsider `json:"outsiders"`
}

Jump to

Keyboard shortcuts

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