Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markovichecha authored and mrexox committed Jun 9, 2022
1 parent f3ffc5b commit 5eff2e6
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 191 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.17
require (
github.com/MakeNowJust/heredoc v1.0.0
github.com/briandowns/spinner v1.18.1
github.com/creack/pty v1.1.17
github.com/gobwas/glob v0.2.3
github.com/google/go-cmp v0.5.6
github.com/kr/pty v1.1.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/mitchellh/mapstructure v1.4.2
github.com/spf13/afero v1.6.0
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -212,7 +214,6 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand Down
19 changes: 11 additions & 8 deletions internal/config/command.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package config

import (
"errors"
"strings"

"github.com/spf13/viper"

"github.com/evilmartians/lefthook/internal/git"
)

var errFilesIncompatible = errors.New("One of your runners contains incompatible file types")

type Command struct {
Run string `mapstructure:"run"`

Expand All @@ -23,21 +26,21 @@ type Command struct {
Runner string `mapstructure:"runner"`
}

func (c Command) Validate() error {
if !isRunnerFilesCompatible(c.Run) {
return errFilesIncompatible
}

return nil
}

func (c Command) DoSkip(gitState git.State) bool {
if value := c.Skip; value != nil {
return isSkip(gitState, value)
}
return false
}

func (c Command) GetRunner() string {
runner := c.Run
if runner == "" {
runner = c.Runner
}
return runner
}

type commandRunReplace struct {
Run string `mapstructure:"run"`
Runner string `mapstructure:"runner"` // DEPRECATED
Expand Down
17 changes: 17 additions & 0 deletions internal/config/files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package config

import "strings"

const (
SubFiles string = "{files}"
SubAllFiles string = "{all_files}"
SubStagedFiles string = "{staged_files}"
PushFiles string = "{push_files}"
)

func isRunnerFilesCompatible(runner string) bool {
if strings.Contains(runner, SubStagedFiles) && strings.Contains(runner, PushFiles) {
return false
}
return true
}
6 changes: 6 additions & 0 deletions internal/config/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package config

import (
"errors"
"os"
"sort"
"strings"

"github.com/spf13/viper"

Expand Down Expand Up @@ -78,6 +80,10 @@ func unmarshalHooks(base, extra *viper.Viper) (*Hook, error) {
return nil, err
}

if tags := os.Getenv("LEFTHOOK_EXCLUDE"); tags != "" {
hook.ExcludeTags = append(hook.ExcludeTags, strings.Split(tags, ",")...)
}

return &hook, nil
}

Expand Down
5 changes: 5 additions & 0 deletions internal/config/load.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -127,5 +128,9 @@ func unmarshalConfigs(base, extra *viper.Viper, c *Config) error {
return err
}

if tags := os.Getenv("LEFTHOOK_QUIET"); tags != "" {
c.SkipOutput = append(c.SkipOutput, strings.Split(tags, ",")...)
}

return nil
}
8 changes: 0 additions & 8 deletions internal/config/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ func (s Script) DoSkip(gitState git.State) bool {
return false
}

func (s Script) GetRunner() string {
runner := s.Runner
if runner == "" {
runner = s.Run
}
return runner
}

type scriptRunnerReplace struct {
Runner string `mapstructure:"runner"`
Run string `mapstructure:"run"` // DEPRECATED
Expand Down
11 changes: 3 additions & 8 deletions internal/lefthook/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const (

type outputDisablerFn func(out ...interface{}) string

func outputDisabler(output string, disabledOutputs []string, envDisabledOutputs []string) outputDisablerFn {
if isOutputDisabled(output, disabledOutputs, envDisabledOutputs) {
func outputDisabler(output string, disabledOutputs []string) outputDisablerFn {
if isOutputDisabled(output, disabledOutputs) {
return func(...interface{}) string {
return ""
}
Expand All @@ -23,16 +23,11 @@ func outputDisabler(output string, disabledOutputs []string, envDisabledOutputs
}
}

func isOutputDisabled(output string, disabledOutputs []string, envDisabledOutputs []string) bool {
func isOutputDisabled(output string, disabledOutputs []string) bool {
for _, disabledOutput := range disabledOutputs {
if output == disabledOutput {
return true
}
}
for _, disabledOutput := range envDisabledOutputs {
if output == disabledOutput {
return true
}
}
return false
}
Loading

0 comments on commit 5eff2e6

Please sign in to comment.