Skip to content

Commit

Permalink
fix by codereview
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex committed Mar 5, 2024
1 parent f4d8b25 commit c96d362
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (c Command) Validate() error {

func (c Command) DoSkip(gitState git.State) bool {
skipChecker := NewSkipChecker(nil)
return skipChecker.DoSkip(gitState, c.Skip, c.Only)
return skipChecker.Check(gitState, c.Skip, c.Only)
}

type commandRunReplace struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (h *Hook) Validate() error {

func (h *Hook) DoSkip(gitState git.State) bool {
skipChecker := NewSkipChecker(nil)
return skipChecker.DoSkip(gitState, h.Skip, h.Only)
return skipChecker.Check(gitState, h.Skip, h.Only)
}

func unmarshalHooks(base, extra *viper.Viper) (*Hook, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/config/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type Script struct {
}

func (s Script) DoSkip(gitState git.State) bool {
skipChecker := NewSkipChecker(nil)
return skipChecker.DoSkip(gitState, s.Skip, s.Only)
skipChecker := NewSkipChecker(NewOsExec())
return skipChecker.Check(gitState, s.Skip, s.Only)
}

type scriptRunnerReplace struct {
Expand Down
8 changes: 5 additions & 3 deletions internal/config/skip.go → internal/config/skip_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewSkipChecker(executor Exec) *SkipChecker {
return &SkipChecker{Executor: executor}
}

func (sc *SkipChecker) DoSkip(gitState git.State, skip interface{}, only interface{}) bool {
func (sc *SkipChecker) Check(gitState git.State, skip interface{}, only interface{}) bool {
if skip != nil {
if sc.matches(gitState, skip) {
return true
Expand Down Expand Up @@ -87,7 +87,9 @@ func (sc *SkipChecker) matchesCommands(typedState map[string]interface{}) bool {
return false
}

log.Debug("[lefthook] skip/only cmd: ", commandLine)
result := sc.Executor.Cmd(commandLine)

return sc.Executor.Cmd(commandLine)
log.Debugf("[lefthook] skip/only cmd: %s, result: %t", commandLine, result)

return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestDoSkip(t *testing.T) {
},
} {
t.Run(tt.name, func(t *testing.T) {
if skipChecker.DoSkip(tt.state, tt.skip, tt.only) != tt.skipped {
if skipChecker.Check(tt.state, tt.skip, tt.only) != tt.skipped {
t.Errorf("Expected: %v, Was %v", tt.skipped, !tt.skipped)
}
})
Expand Down

0 comments on commit c96d362

Please sign in to comment.