-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
58 lines (45 loc) · 1.07 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
package main
import (
"encoding/json"
"errors"
"os"
"path"
"github.com/mitchellh/go-homedir"
)
type Config struct {
GithubToken string `json:"githubToken"`
Repos []struct {
Name string `json:"name"`
MergeInto string `json:"mergeInto"`
} `json:"repos"`
}
var (
ErrMissingConfigFile = errors.New("couldnt find config file")
ErrMissingGithubToken = errors.New("missing githubToken in config")
)
func readConfiguration(providedPath string) (conf Config, err error) {
if dir, e := homedir.Dir(); e == nil {
expandedPath := path.Join(dir, providedPath)
if fConf, e := os.Open(expandedPath); e == nil {
defer fConf.Close()
err = json.NewDecoder(fConf).Decode(&conf)
}
} else {
err = ErrMissingConfigFile
return
}
if conf.GithubToken == "" {
err = ErrMissingGithubToken
return
}
return
}
func (conf Config) getRepoMergeInto(namespace, repo, defaulted string) string {
qualifier := namespace + ":" + repo
for _, repo := range conf.Repos {
if repo.Name == qualifier && repo.MergeInto != "" {
return repo.MergeInto
}
}
return defaulted
}