forked from tkuchiki/ghooks-cmd-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
70 lines (56 loc) · 1.25 KB
/
config.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/BurntSushi/toml"
"io/ioutil"
)
type config struct {
Port int `toml:"port"`
Host string `toml:"host"`
Secret string `toml:"secret"`
Logfile string `toml:"logfile"`
Pidfile string `toml:"pidfile"`
Hook []hook
}
type hook struct {
Event string `toml:"event"`
Cmd string `toml:"command"`
Branch string `toml:"branch"`
IncludeActions []string `toml:"include_actions"`
ExcludeActions []string `toml:"exclude_actions"`
AccessToken string `toml:"access_token"`
}
type hooks struct {
Hook []hook
}
func loadFile(filename string) (string, error) {
var err error
buf, err := ioutil.ReadFile(filename)
return string(buf), err
}
func loadToml(filename string, c config) (config, error) {
var config config
buf, err := loadFile(filename)
if err != nil {
return config, err
}
_, err = toml.Decode(string(buf), &config)
if err != nil {
return config, err
}
if config.Port == 0 {
config.Port = c.Port
}
if config.Host == "" {
config.Host = c.Host
}
if config.Logfile == "" {
config.Logfile = c.Logfile
}
if config.Pidfile == "" {
config.Pidfile = c.Pidfile
}
return config, err
}
func (h hook) isNotBlankAccessToken() bool {
return h.AccessToken != ""
}