-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
60 lines (45 loc) · 1.47 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
package main
import (
"errors"
"fmt"
"io/fs"
"os"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
)
type configFile struct {
DiableTagSigning bool `yaml:"disable_signed_tags"`
MatchMajor []string `yaml:"match_major"`
MatchPatch []string `yaml:"match_patch"`
ReleaseCommitMessage string `yaml:"release_commit_message"`
IgnoreMessages []string `yaml:"ignore_messages"`
PreCommitCommands []string `yaml:"pre_commit_commands"`
}
func loadConfig(configFiles ...string) (*configFile, error) {
var err error
c := &configFile{}
if err = yaml.Unmarshal(mustAsset("assets/git_changerelease.yaml"), c); err != nil {
return nil, fmt.Errorf("unmarshalling default config: %w", err)
}
for _, fn := range configFiles {
if _, err = os.Stat(fn); err != nil {
if errors.Is(err, fs.ErrNotExist) {
logrus.WithField("path", fn).Debug("config-file does not exist, skipping")
continue
}
return nil, fmt.Errorf("getting config-file stat for %q: %w", fn, err)
}
logrus.WithField("path", fn).Debug("loading config-file")
dataFile, err := os.Open(fn) //#nosec:G304 // This is intended to load variable files
if err != nil {
return nil, fmt.Errorf("opening config file: %w", err)
}
if err = yaml.NewDecoder(dataFile).Decode(c); err != nil {
return c, fmt.Errorf("decoding config file: %w", err)
}
if err := dataFile.Close(); err != nil {
logrus.WithError(err).WithField("path", fn).Debug("closing config file (leaked fd)")
}
}
return c, nil
}