logginghandler/vendor/github.com/goreleaser/chglog/files.go
Marvin Preuss d095180eb4
All checks were successful
continuous-integration/drone/push Build is passing
build: uses go modules for tool handling
2022-01-14 13:51:56 +01:00

37 lines
787 B
Go

package chglog
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
// Parse parse a changelog.yml into ChangeLogEntries.
func Parse(file string) (entries ChangeLogEntries, err error) {
var (
body []byte
)
body, err = ioutil.ReadFile(file) // nolint: gosec,gocritic
switch {
case os.IsNotExist(err):
return make(ChangeLogEntries, 0), nil
case err != nil:
return nil, fmt.Errorf("error parsing %s: %w", file, err)
}
if err = yaml.Unmarshal(body, &entries); err != nil {
return entries, fmt.Errorf("error parsing %s: %w", file, err)
}
return entries, nil
}
// Save save ChangeLogEntries to a yml file.
func (c *ChangeLogEntries) Save(file string) (err error) {
data, _ := yaml.Marshal(c)
// nolint: gosec,gocritic
return ioutil.WriteFile(file, data, 0644)
}