/
hooks.go
55 lines (48 loc) 路 1.12 KB
/
hooks.go
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
package hooks
import "fmt"
type Hooks interface {
Init(map[string]string) error
Name() string
Version() string
Success(*SuccessHookConfig) error
NoRelease(*NoReleaseConfig) error
}
type ChainedHooksExecutor struct {
HooksChain []Hooks
}
func (c *ChainedHooksExecutor) Success(config *SuccessHookConfig) error {
for _, h := range c.HooksChain {
name := h.Name()
err := h.Success(config)
if err != nil {
return fmt.Errorf("%s hook has failed: %w", name, err)
}
}
return nil
}
func (c *ChainedHooksExecutor) NoRelease(config *NoReleaseConfig) error {
for _, h := range c.HooksChain {
name := h.Name()
err := h.NoRelease(config)
if err != nil {
return fmt.Errorf("%s hook has failed: %w", name, err)
}
}
return nil
}
func (c *ChainedHooksExecutor) Init(conf map[string]string) error {
for _, h := range c.HooksChain {
err := h.Init(conf)
if err != nil {
return err
}
}
return nil
}
func (c *ChainedHooksExecutor) GetNameVersionPairs() []string {
ret := make([]string, len(c.HooksChain))
for i, h := range c.HooksChain {
ret[i] = fmt.Sprintf("%s@%s", h.Name(), h.Version())
}
return ret
}