• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evilmartians / lefthook / 17762708138

16 Sep 2025 10:23AM UTC coverage: 71.322% (-2.7%) from 73.996%
17762708138

push

github

web-flow
refactor: reduce the amount of code in a single file (#1131)

* refactor: reduce the amount of code in a single file

251 of 302 new or added lines in 5 files covered. (83.11%)

154 existing lines in 5 files now uncovered.

3457 of 4847 relevant lines covered (71.32%)

3.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/internal/run/controller/command/build.go
1
package command
2

3
import (
4
        "github.com/evilmartians/lefthook/internal/config"
5
        "github.com/evilmartians/lefthook/internal/git"
6
        "github.com/evilmartians/lefthook/internal/run/controller/utils"
7
        "github.com/evilmartians/lefthook/internal/system"
8
)
9

10
type JobParams struct {
11
        Name         string
12
        Run          string
13
        Root         string
14
        Runner       string
15
        Script       string
16
        FilesCmd     string
17
        FileTypes    []string
18
        Tags         []string
19
        Glob         []string
20
        ExcludeFiles interface{}
21
        Only         interface{}
22
        Skip         interface{}
23
}
24

25
type BuilderOptions struct {
26
        HookName    string
27
        ExcludeTags []string
28
        GitArgs     []string
29
        ForceFiles  []string
30
        SourceDirs  []string
31
        OnlyTags    []string
32
        Templates   map[string]string
33
        Force       bool
34
}
35

36
type Builder struct {
37
        git  *git.Repository
38
        opts BuilderOptions
39
}
40

41
func NewBuilder(repo *git.Repository, opts BuilderOptions) *Builder {
3✔
42
        return &Builder{
3✔
43
                git:  repo,
3✔
44
                opts: opts,
3✔
45
        }
3✔
46
}
3✔
47

48
// BuildCommands returns the list of commands and the list of files touched by the command.
49
func (b *Builder) BuildCommands(params *JobParams) ([]string, []string, error) {
3✔
50
        if reason := b.skipReason(params); len(reason) > 0 {
6✔
51
                return nil, nil, SkipError{reason}
3✔
52
        }
3✔
53

54
        if len(params.Run) != 0 {
6✔
55
                return b.buildCommand(params)
3✔
56
        } else {
6✔
57
                return b.buildScript(params)
3✔
58
        }
3✔
59
}
60

61
func (b *Builder) skipReason(params *JobParams) string {
3✔
62
        skipChecker := config.NewSkipChecker(system.Cmd)
3✔
63
        if skipChecker.Check(b.git.State, params.Skip, params.Only) {
6✔
64
                return "by condition"
3✔
65
        }
3✔
66

67
        if len(b.opts.OnlyTags) > 0 && !utils.Intersect(b.opts.OnlyTags, params.Tags) {
6✔
68
                return "tags"
3✔
69
        }
3✔
70

71
        if utils.Intersect(b.opts.ExcludeTags, params.Tags) {
3✔
NEW
72
                return "tags"
×
NEW
73
        }
×
74

75
        if utils.Intersect(b.opts.ExcludeTags, []string{params.Name}) {
3✔
NEW
76
                return "name"
×
NEW
77
        }
×
78

79
        return ""
3✔
80
}
81

82
func (p *JobParams) validateCommand() error {
3✔
83
        if !config.IsRunFilesCompatible(p.Run) {
3✔
NEW
84
                return config.ErrFilesIncompatible
×
NEW
85
        }
×
86

87
        return nil
3✔
88
}
89

90
func (p *JobParams) validateScript() error {
3✔
91
        return nil
3✔
92
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc