Skip to content

Golang package for changelog 🔖 creation/parsing

License

Notifications You must be signed in to change notification settings

GHCICD/go-changelog

 
 

Repository files navigation

go-changelog

Go Reference Code Coverage Go Report Card Release License

Golang package for changelog file creation/parsing

Features

Manual

  • Install with go get -u github.com/anton-yurchenko/go-changelog

Examples

Create a changelog file

package main

import (
    changelog "github.com/anton-yurchenko/go-changelog"
)

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.CreateReleaseFromUnreleased("1.0.0", "https://github.com/anton-yurchenko/go-changelog/releases/tag/v1.0.0", "2021-05-31")
    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("./CHANGELOG.md"); err != nil {
        panic(err)
    }
}

Parse an existing changelog file

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

Update an existing changelog file

Click to expand
package main

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

    r := c.GetRelease("1.2.1")
    if r == nil {
        panic("Release does not exists")
    }

    r.Yanked = true

    c.SaveToFile("./CHANGELOG.md")
    if err != nil {
        panic(err)
    }
}

Notes

  • Releases are sorted by their Semantic Version
  • Scopes are sorted by their importance

License

MIT © 2021-present Anton Yurchenko

About

Golang package for changelog 🔖 creation/parsing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.9%
  • Makefile 1.1%