validate

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RegisteredRules are the avaible validation to perform on git commits
	RegisteredRules = []Rule{}
)

Functions

func RegisterRule

func RegisterRule(vr Rule)

RegisterRule includes the Rule in the avaible set to use

func SanitizeFilters

func SanitizeFilters(filtStr string) (filters []string)

SanitizeFilters takes a comma delimited list and returns the trimmend and split (on ",") items in the list

func StringsSliceContains

func StringsSliceContains(a []string, b string) bool

StringsSliceContains checks for the presence of a word in string array

func StringsSliceEqual

func StringsSliceEqual(a, b []string) bool

StringsSliceEqual compares two string arrays for equality

Types

type Result

type Result struct {
	CommitEntry git.CommitEntry
	Pass        bool
	Msg         string
}

Result is the result for a single validation of a commit.

type Results

type Results []Result

Results is a set of results. This is type makes it easy for the following function.

func Commit

func Commit(c git.CommitEntry, rules []Rule) Results

Commit processes the given rules on the provided commit, and returns the result set.

func (Results) PassFail

func (vr Results) PassFail() (pass int, fail int)

PassFail gives a quick over/under of passes and failures of the results in this set

type Rule

type Rule struct {
	Name        string // short name for reference in in the `-run=...` flag
	Value       string // value to configure for the rule (i.e. a regexp to check for in the commit message)
	Description string // longer Description for readability
	Run         func(Rule, git.CommitEntry) Result
	Default     bool // whether the registered rule is run by default
}

Rule will operate over a provided git.CommitEntry, and return a result.

func FilterRules

func FilterRules(rules []Rule, includes []string) []Rule

FilterRules takes a set of rules and a list of short names to include, and returns the reduced set. The comparison is case insensitive.

Some `includes` rules have values assigned to them. i.e. -run "dco,message_regexp='^JIRA-[0-9]+ [A-Z].*$'"

type Runner

type Runner struct {
	Root        string
	Rules       []Rule
	Results     Results
	Verbose     bool
	CommitRange string // if this is empty, then it will default to FETCH_HEAD, then HEAD
}

Runner is the for processing a set of rules against a range of commits

func NewRunner

func NewRunner(root string, rules []Rule, commitrange string, verbose bool) (*Runner, error)

NewRunner returns an initiallized Runner.

func (*Runner) Run

func (r *Runner) Run() error

Run processes the rules for each commit in the range provided

Jump to

Keyboard shortcuts

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