changelog

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2021 License: MIT Imports: 10 Imported by: 1

README

go-changelog

Go Reference Code Coverage Go Report Card Release License

Golang package for parsing a changelog file

Overview

go-changelog support changelog files compliant with Common Changelog and Keep a Changelog.

Manual

  1. Install with go get -u github.com/anton-yurchenko/go-changelog
  2. Create a parser by providing a changelog file path to it and parse the content:
package main

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

func main() {
    parser, err := changelog.NewParser("./CHANGELOG.md")
    if err != nil {
        panic(err)
    }

    changelog, err := parser.Parse()
    if err != nil {
        panic(err)
    }

    fmt.Printf("Changelog contains %v releases", len(changelog.Releases))
}

License

MIT © 2021-present Anton Yurchenko

Documentation

Index

Constants

View Source
const (
	// General
	EmptyLineRegex string = `^\s*$`
	URLRegex       string = `` /* 242-byte string literal not displayed */
	SemVerRegex    string = `` /* 177-byte string literal not displayed */
	DateRegex      string = `([1-2][0-9][0-9][0-9])-([1-9]|[0][1-9]|[1][0-2])-([1-9]|[0][1-9]|[1-2][0-9]?|[3][0-1]?)`
	// Margins
	TitleRegex                       string = `^#\s*(?P<title>\S*)\s*$`
	UnreleasedTitleRegex             string = `^## \[(?P<title>Unreleased)\]$`
	UnreleasedTitleWithLinkRegex     string = `^## \[(?P<title>Unreleased)\]\((?P<url>` + URLRegex + `)\)$`
	VersionTitleRegex                string = `^## \[(?P<version>` + SemVerRegex + `)\] - (?P<date>` + DateRegex + `)$`
	VersionTitleWithLinkRegex        string = `^## \[(?P<version>` + SemVerRegex + `)\]\((?P<url>` + URLRegex + `)\) - (?P<date>` + DateRegex + `)$`
	MarkdownUnreleasedTitleLinkRegex string = `^\[(?P<title>Unreleased)\]: (?P<url>` + URLRegex + `)$`
	MarkdownVersionTitleLinkRegex    string = `^\[(?P<version>` + SemVerRegex + `)\]: (?P<url>` + URLRegex + `)$`
	// Scopes
	AddedScopeRegex      string = `^### (?P<scope>Added)$`
	ChangedScopeRegex    string = `^### (?P<scope>Changed)$`
	DeprecatedScopeRegex string = `^### (?P<scope>Deprecated)$`
	RemovedScopeRegex    string = `^### (?P<scope>Removed)$`
	FixedScopeRegex      string = `^### (?P<scope>Fixed)$`
	SecurityScopeRegex   string = `^### (?P<scope>Security)$`
	EntryRegex           string = `^(?P<marker>[-*+]\s*)(?P<entry>.*)$`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Changelog

type Changelog struct {
	Title       *string
	Description *string
	Unreleased  *Release
	Releases    []*Release
}

Changelog reflects content of a complete changelog file

type Changes

type Changes struct {
	Notice     *string
	Added      *[]string
	Changed    *[]string
	Deprecated *[]string
	Removed    *[]string
	Fixed      *[]string
	Security   *[]string
}

Changes are scoped changelog entries for a single version.

type Filesystem added in v0.0.2

type Filesystem interface {
	Stat(string) (fs.FileInfo, error)
	Open(string) (afero.File, error)
}

type Parser

type Parser struct {
	Filepath   string
	Filesystem Filesystem
	Buffer     []string
	Margins    struct {
		Lines      []int
		Title      *int
		Unreleased *int
		Releases   []int
		Links      []int
		Added      []int
		Changed    []int
		Deprecated []int
		Removed    []int
		Fixed      []int
		Security   []int
	}
}

Parser is basically a runtime that holds a raw changelog content, key file Margins, filesystem backend and other attributes.

func NewParser

func NewParser(filepath string) (*Parser, error)

NewParser creates a new Changelog Parser.

func NewParserWithFilesystem

func NewParserWithFilesystem(filesystem Filesystem, filepath string) (*Parser, error)

NewParser creates a new Changelog Parser using non default (OS) filesystem. Possible options for `filesystems` are: [`afero.NewOsFs()`,`afero.NewMemMapFs()`]

func (*Parser) Parse

func (p *Parser) Parse() (*Changelog, error)

Parse a changelog file and return a Changelog struct

type Release

type Release struct {
	Version *string
	Date    *time.Time
	URL     *string
	Changes *Changes
}

Release is a single version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL