Golang package for changelog file creation/parsing
- Supports Semantic Version
- Keep a Changelog Compliant
- Common Changelog Compliant
- Install with
go get -u github.com/anton-yurchenko/go-changelog
package main
import (
changelog "github.com/anton-yurchenko/go-changelog"
"github.com/spf13/afero"
)
func main() {
c := changelog.NewChangelog()
c.SetTitle("Changelog")
c.SetDescription("This file contains changes of all releases")
c.AddUnreleasedChange("fixed", []string{"Bug"})
c.AddUnreleasedChange("added", []string{"Feature"})
r, err := c.CreateReleaseFromUnreleasedWithURL("1.0.0", "2021-05-31","https://github.com/anton-yurchenko/go-changelog/releases/tag/v1.0.0")
if err != nil {
panic(err)
}
if err := r.AddChange("changed", "User API"); err != nil {
panic(err)
}
r.AddNotice("**This release contains breaking changes**")
if err := c.SaveToFile(afero.NewOsFs(), "./CHANGELOG.md"); err != nil {
panic(err)
}
}
package main
import (
"fmt"
changelog "github.com/anton-yurchenko/go-changelog"
)
func main() {
p, err := changelog.NewParser("./CHANGELOG.md")
if err != nil {
panic(err)
}
c, err := p.Parse()
if err != nil {
panic(err)
}
fmt.Printf("Changelog contains %v releases", c.Releases.Len())
}
Click to expand
package main
import (
changelog "github.com/anton-yurchenko/go-changelog"
"github.com/spf13/afero"
)
func main() {
p, err := changelog.NewParser("./CHANGELOG.md")
if err != nil {
panic(err)
}
c, err := p.Parse()
if err != nil {
panic(err)
}
r := c.GetRelease("1.2.1")
if r == nil {
panic("Release does not exists")
}
r.Yanked = true
c.SaveToFile(afero.NewOsFs(), "./CHANGELOG.md")
if err != nil {
panic(err)
}
}
- Releases are sorted by their Semantic Version
- Scopes are sorted by their importance
SaveToFile
will overwrite the existing file, and anything that does not match the changelog format will be omitted
MIT © 2021-present Anton Yurchenko