-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfiles.go
More file actions
33 lines (27 loc) · 762 Bytes
/
files.go
File metadata and controls
33 lines (27 loc) · 762 Bytes
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
package chglog
import (
"fmt"
"os"
"go.yaml.in/yaml/v3"
)
// Parse parse a changelog.yml into ChangeLogEntries.
func Parse(file string) (entries ChangeLogEntries, err error) {
var body []byte
body, err = os.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 os.WriteFile(file, data, 0o644)
}