forked from siderolabs/kres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
78 lines (61 loc) · 1.86 KB
/
Copy pathconfig.go
File metadata and controls
78 lines (61 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package lefthook
// Config is a declarative description of lefthook.yml contributions, suitable
// for unmarshalling from a kres.yaml block.
//
// Hooks reuse the very same builder types (Hook, Command, Job, Group) that
// serialize lefthook.yml, so the config is authored in lefthook's native schema
// and there is a single definitive set of types for both serializing the output
// and deserializing the config.
type Config struct {
Hooks map[string]*Hook `yaml:"hooks"`
Enabled bool `yaml:"enabled"`
}
// Compile merges the configured hooks into the output. It is a no-op when the
// config is disabled.
func (c Config) Compile(output *Output) error {
if !c.Enabled {
return nil
}
for name, cfgHook := range c.Hooks {
if cfgHook == nil {
continue
}
hook := output.Hook(name)
if cfgHook.Parallel != nil {
hook.WithParallel(*cfgHook.Parallel)
}
if cfgHook.Piped {
hook.WithPiped(true)
}
for cmdName, cmd := range cfgHook.Commands {
if cmd == nil {
continue
}
*hook.Command(cmdName) = *cmd
}
for _, job := range cfgHook.Jobs {
if job == nil {
continue
}
// A named job wrapping a group is merged into the hook's group of
// the same name, so a config can extend the shared fix/lint groups
// emitted by the standard blocks instead of forking a new one.
if job.Group != nil && job.Name != "" {
group := hook.Group(job.Name)
if job.Group.Parallel != nil {
group.WithParallel(*job.Group.Parallel)
}
if job.Group.Piped {
group.WithPiped(true)
}
group.Jobs = append(group.Jobs, job.Group.Jobs...)
continue
}
hook.Jobs = append(hook.Jobs, job)
}
}
return nil
}