mirror of
https://github.com/adnanh/webhook.git
synced 2025-08-01 15:30:30 +00:00
fix: revert #1
This commit is contained in:
parent
5a3828e4dd
commit
3285d30374
3 changed files with 11 additions and 20 deletions
|
@ -816,13 +816,7 @@ func (h *Hooks) LoadFromFile(path string, asTemplate bool) error {
|
|||
file = buf.Bytes()
|
||||
}
|
||||
|
||||
toJSON, err := yaml.YAMLToJSON(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonDecoder := json.NewDecoder(bytes.NewBuffer(toJSON))
|
||||
jsonDecoder.DisallowUnknownFields()
|
||||
return jsonDecoder.Decode(h)
|
||||
return yaml.Unmarshal(file, h)
|
||||
}
|
||||
|
||||
// Append appends hooks unless the new hooks contain a hook with an ID that already exists
|
||||
|
|
|
@ -491,7 +491,6 @@ var hooksLoadFromFileTests = []struct {
|
|||
{"", false, true},
|
||||
// failures
|
||||
{"missing.json", false, false},
|
||||
{"testdata/unrecognized.yaml", false, false},
|
||||
}
|
||||
|
||||
func TestHooksLoadFromFile(t *testing.T) {
|
||||
|
@ -501,7 +500,6 @@ func TestHooksLoadFromFile(t *testing.T) {
|
|||
for _, tt := range hooksLoadFromFileTests {
|
||||
h := &Hooks{}
|
||||
err := h.LoadFromFile(tt.path, tt.asTemplate)
|
||||
t.Log(err)
|
||||
if (err == nil) != tt.ok {
|
||||
t.Errorf(err.Error())
|
||||
}
|
||||
|
|
21
webhook.go
21
webhook.go
|
@ -206,21 +206,20 @@ func main() {
|
|||
newHooks := hook.Hooks{}
|
||||
|
||||
err := newHooks.LoadFromFile(hooksFilePath, *asTemplate)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't load hooks from file! %+v\n", err)
|
||||
}
|
||||
log.Printf("couldn't load hooks from file! %+v\n", err)
|
||||
} else {
|
||||
log.Printf("found %d hook(s) in file\n", len(newHooks))
|
||||
|
||||
log.Printf("found %d hook(s) in file\n", len(newHooks))
|
||||
|
||||
for _, hook := range newHooks {
|
||||
if matchLoadedHook(hook.ID) != nil {
|
||||
log.Fatalf("error: hook with the id %s has already been loaded!\nplease check your hooks file for duplicate hooks ids!\n", hook.ID)
|
||||
for _, hook := range newHooks {
|
||||
if matchLoadedHook(hook.ID) != nil {
|
||||
log.Fatalf("error: hook with the id %s has already been loaded!\nplease check your hooks file for duplicate hooks ids!\n", hook.ID)
|
||||
}
|
||||
log.Printf("\tloaded: %s\n", hook.ID)
|
||||
}
|
||||
log.Printf("\tloaded: %s\n", hook.ID)
|
||||
}
|
||||
|
||||
loadedHooksFromFiles[hooksFilePath] = newHooks
|
||||
loadedHooksFromFiles[hooksFilePath] = newHooks
|
||||
}
|
||||
}
|
||||
|
||||
newHooksFiles := hooksFiles[:0]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue