Skip to content

Commit 268f088

Browse files
committed
MEDIUM: add config file support
1 parent b044c96 commit 268f088

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

check-commit/check.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package main
33
import (
44
"bytes"
55
"fmt"
6-
yaml "gopkg.in/yaml.v2"
6+
"io/ioutil"
77
"log"
88
"os"
99
"os/exec"
1010
"regexp"
1111
"strings"
12+
13+
yaml "gopkg.in/yaml.v2"
1214
)
1315

1416
const guidelinesLink = "Please refer to https://github.com/haproxy/haproxy/blob/master/CONTRIBUTING#L632"
@@ -181,11 +183,22 @@ func readGitEnvironment() (*gitEnv, error) {
181183
}
182184

183185
func main() {
186+
var config string
187+
if data, err := ioutil.ReadFile(".check-commit.yml"); err == nil {
188+
config = string(data)
189+
} else {
190+
log.Printf("no config found, using built-in fallback configuration (HAProxy defaults)")
191+
config = defaultConf
192+
}
184193

185-
if err := yaml.Unmarshal([]byte(defaultConf), &myConfig); err != nil {
194+
if err := yaml.Unmarshal([]byte(config), &myConfig); err != nil {
186195
log.Fatalf("error reading configuration: %s", err)
187196
}
188-
fmt.Printf("%s\n", myConfig)
197+
c1, _ := yaml.Marshal(myConfig)
198+
c2, _ := yaml.Marshal(prgConfig{}) // empty config
199+
if string(c1) == string(c2) {
200+
log.Printf("WARNING: using empty configuration (i.e. no verification)")
201+
}
189202

190203
var out []byte
191204

0 commit comments

Comments
 (0)