diff --git a/internal/config/command.go b/internal/config/command.go index 37b93f5d..dfdc6c07 100644 --- a/internal/config/command.go +++ b/internal/config/command.go @@ -31,6 +31,10 @@ type Command struct { StageFixed bool `json:"stage_fixed,omitempty" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"` } +type commandRunReplace struct { + Run string `mapstructure:"run"` +} + func (c Command) Validate() error { if !isRunnerFilesCompatible(c.Run) { return errFilesIncompatible @@ -44,14 +48,10 @@ func (c Command) DoSkip(gitState git.State) bool { return skipChecker.Check(gitState, c.Skip, c.Only) } -func (c Command) GetPriority() int { +func (c Command) ExecutionPriority() int { return c.Priority } -type commandRunReplace struct { - Run string `mapstructure:"run"` -} - func mergeCommands(base, extra *viper.Viper) (map[string]*Command, error) { if base == nil && extra == nil { return nil, nil diff --git a/internal/config/script.go b/internal/config/script.go index 5505b18a..fe443ecd 100644 --- a/internal/config/script.go +++ b/internal/config/script.go @@ -24,16 +24,16 @@ type Script struct { StageFixed bool `json:"stage_fixed,omitempty" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"` } +type scriptRunnerReplace struct { + Runner string `mapstructure:"runner"` +} + func (s Script) DoSkip(gitState git.State) bool { skipChecker := NewSkipChecker(NewOsExec()) return skipChecker.Check(gitState, s.Skip, s.Only) } -type scriptRunnerReplace struct { - Runner string `mapstructure:"runner"` -} - -func (s Script) GetPriority() int { +func (s Script) ExecutionPriority() int { return s.Priority } diff --git a/internal/lefthook/run/runner.go b/internal/lefthook/run/runner.go index 8315a4ae..265fa2e4 100644 --- a/internal/lefthook/run/runner.go +++ b/internal/lefthook/run/runner.go @@ -68,7 +68,7 @@ func NewRunner(opts Options) *Runner { type executable interface { *config.Command | *config.Script - GetPriority() int + ExecutionPriority() int } // RunAll runs scripts and commands. @@ -546,29 +546,29 @@ func (r *Runner) logExecute(name string, err error, out io.Reader) { } } -// sortByPriority sorts the names by preceding numbers if they occur and special priority if it is set. +// sortByPriority sorts the tags by preceding numbers if they occur and special priority if it is set. // If the names starts with letter the command name will be sorted alphabetically. // If there's a `priority` field defined for a command or script it will be used instead of alphanumeric sorting. // // []string{"1_command", "10command", "3 command", "command5"} // -> 1_command, 3 command, 10command, command5 -func sortByPriority[E executable](array []string, exe map[string]E) { - sort.SliceStable(array, func(i, j int) bool { - exeI, iOk := exe[array[i]] - exeJ, jOk := exe[array[j]] +func sortByPriority[E executable](tags []string, executables map[string]E) { + sort.SliceStable(tags, func(i, j int) bool { + exeI, okI := executables[tags[i]] + exeJ, okJ := executables[tags[j]] - if iOk && exeI.GetPriority() != 0 || jOk && exeJ.GetPriority() != 0 { - if !iOk || exeI.GetPriority() == 0 { + if okI && exeI.ExecutionPriority() != 0 || okJ && exeJ.ExecutionPriority() != 0 { + if !okI || exeI.ExecutionPriority() == 0 { return false } - if !jOk || exeJ.GetPriority() == 0 { + if !okJ || exeJ.ExecutionPriority() == 0 { return true } - return exeI.GetPriority() < exeJ.GetPriority() + return exeI.ExecutionPriority() < exeJ.ExecutionPriority() } numEnds := -1 - for idx, ch := range array[i] { + for idx, ch := range tags[i] { if unicode.IsDigit(ch) { numEnds = idx } else { @@ -576,15 +576,15 @@ func sortByPriority[E executable](array []string, exe map[string]E) { } } if numEnds == -1 { - return array[i] < array[j] + return tags[i] < tags[j] } - numI, err := strconv.Atoi(array[i][:numEnds+1]) + numI, err := strconv.Atoi(tags[i][:numEnds+1]) if err != nil { - return array[i] < array[j] + return tags[i] < tags[j] } numEnds = -1 - for idx, ch := range array[j] { + for idx, ch := range tags[j] { if unicode.IsDigit(ch) { numEnds = idx } else { @@ -594,7 +594,7 @@ func sortByPriority[E executable](array []string, exe map[string]E) { if numEnds == -1 { return true } - numJ, err := strconv.Atoi(array[j][:numEnds+1]) + numJ, err := strconv.Atoi(tags[j][:numEnds+1]) if err != nil { return true }