fix: revert #1

This commit is contained in:
soulteary 2023-01-09 23:00:00 +08:00
parent 5a3828e4dd
commit 3285d30374
No known key found for this signature in database
GPG key ID: 8107DBA6BC84D986
3 changed files with 11 additions and 20 deletions

View file

@ -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

View file

@ -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())
}

View file

@ -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]