• 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

0.0
/internal/run/controller/jobs/build_script.go
1
package jobs
2

3
import (
4
        "fmt"
5
        "os"
6
        "path/filepath"
7
        "strings"
8

9
        "github.com/alessio/shellescape"
10

11
        "github.com/evilmartians/lefthook/internal/log"
12
)
13

14
const (
15
        executableFileMode os.FileMode = 0o751
16
        executableMask     os.FileMode = 0o111
17
)
18

19
type scriptNotExistsError struct {
20
        scriptPath string
21
}
22

23
func (s scriptNotExistsError) Error() string {
×
24
        return fmt.Sprintf("script does not exist: %s", s.scriptPath)
×
25
}
×
26

UNCOV
27
func buildScript(params *Params, settings *Settings) ([]string, []string, error) {
×
UNCOV
28
        if err := params.validateScript(); err != nil {
×
29
                return nil, nil, err
×
30
        }
×
31

UNCOV
32
        var scriptExists bool
×
UNCOV
33
        execs := make([]string, 0)
×
UNCOV
34
        for _, sourceDir := range settings.SourceDirs {
×
UNCOV
35
                scriptPath := filepath.Join(sourceDir, settings.HookName, params.Script)
×
UNCOV
36
                fileInfo, err := settings.Repo.Fs.Stat(scriptPath)
×
UNCOV
37
                if os.IsNotExist(err) {
×
UNCOV
38
                        log.Debugf("[lefthook] script doesn't exist: %s", scriptPath)
×
UNCOV
39
                        continue
×
40
                }
UNCOV
41
                if err != nil {
×
42
                        log.Errorf("Failed to get info about a script: %s", params.Script)
×
43
                        return nil, nil, err
×
44
                }
×
45

UNCOV
46
                scriptExists = true
×
UNCOV
47

×
UNCOV
48
                if !fileInfo.Mode().IsRegular() {
×
49
                        log.Debugf("[lefthook] script '%s' is not a regular file, skipping", scriptPath)
×
50
                        return nil, nil, SkipError{"not a regular file"}
×
51
                }
×
52

53
                // Make sure file is executable
UNCOV
54
                if (fileInfo.Mode() & executableMask) == 0 {
×
UNCOV
55
                        if err := settings.Repo.Fs.Chmod(scriptPath, executableFileMode); err != nil {
×
56
                                log.Errorf("Couldn't change file mode to make file executable: %s", err)
×
57
                                return nil, nil, err
×
58
                        }
×
59
                }
60

UNCOV
61
                var args []string
×
UNCOV
62
                if len(params.Runner) > 0 {
×
UNCOV
63
                        args = append(args, params.Runner)
×
UNCOV
64
                }
×
65

UNCOV
66
                args = append(args, shellescape.Quote(scriptPath))
×
UNCOV
67
                args = append(args, settings.GitArgs...)
×
UNCOV
68

×
UNCOV
69
                execs = append(execs, strings.Join(args, " "))
×
70
        }
71

UNCOV
72
        if !scriptExists {
×
73
                return nil, nil, scriptNotExistsError{params.Script}
×
74
        }
×
75

UNCOV
76
        return execs, nil, nil
×
77
}
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