mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-21 12:00:40 +00:00
Merge pull request #41 from bvieira/support-non-versioned-tags
Feature: Support non versioned tags
This commit is contained in:
commit
6b4948b103
10
Makefile
10
Makefile
@ -80,6 +80,10 @@ endif
|
||||
release-all:
|
||||
@rm -rf bin
|
||||
|
||||
VERSION=$(shell git sv nv) BUILDOS=linux make release
|
||||
VERSION=$(shell git sv nv) BUILDOS=darwin make release
|
||||
VERSION=$(shell git sv nv) COMPRESS_TYPE=zip BUILDOS=windows make release
|
||||
VERSION=$(shell git sv nv) BUILDOS=linux BUILDARCH=amd64 make release
|
||||
VERSION=$(shell git sv nv) BUILDOS=darwin BUILDARCH=amd64 make release
|
||||
VERSION=$(shell git sv nv) COMPRESS_TYPE=zip BUILDOS=windows BUILDARCH=amd64 make release
|
||||
|
||||
VERSION=$(shell git sv nv) BUILDOS=linux BUILDARCH=arm64 make release
|
||||
VERSION=$(shell git sv nv) BUILDOS=darwin BUILDARCH=arm64 make release
|
||||
VERSION=$(shell git sv nv) COMPRESS_TYPE=zip BUILDOS=windows BUILDARCH=arm64 make release
|
||||
|
@ -148,7 +148,7 @@ func commitNotesHandler(git sv.Git, rnProcessor sv.ReleaseNoteProcessor, outputF
|
||||
date, _ = time.Parse("2006-01-02", commits[0].Date)
|
||||
}
|
||||
|
||||
output, err := outputFormatter.FormatReleaseNote(rnProcessor.Create(nil, date, commits))
|
||||
output, err := outputFormatter.FormatReleaseNote(rnProcessor.Create(nil, "", date, commits))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not format release notes, message: %v", err)
|
||||
}
|
||||
@ -160,11 +160,12 @@ func commitNotesHandler(git sv.Git, rnProcessor sv.ReleaseNoteProcessor, outputF
|
||||
func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnProcessor sv.ReleaseNoteProcessor, outputFormatter sv.OutputFormatter) func(c *cli.Context) error {
|
||||
return func(c *cli.Context) error {
|
||||
var commits []sv.GitCommitLog
|
||||
var rnVersion semver.Version
|
||||
var rnVersion *semver.Version
|
||||
var tag string
|
||||
var date time.Time
|
||||
var err error
|
||||
|
||||
if tag := c.String("t"); tag != "" {
|
||||
if tag = c.String("t"); tag != "" {
|
||||
rnVersion, date, commits, err = getTagVersionInfo(git, tag)
|
||||
} else {
|
||||
// TODO: should generate release notes if version was not updated?
|
||||
@ -175,7 +176,7 @@ func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor,
|
||||
return err
|
||||
}
|
||||
|
||||
releasenote := rnProcessor.Create(&rnVersion, date, commits)
|
||||
releasenote := rnProcessor.Create(rnVersion, tag, date, commits)
|
||||
output, err := outputFormatter.FormatReleaseNote(releasenote)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not format release notes, message: %v", err)
|
||||
@ -185,20 +186,17 @@ func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor,
|
||||
}
|
||||
}
|
||||
|
||||
func getTagVersionInfo(git sv.Git, tag string) (semver.Version, time.Time, []sv.GitCommitLog, error) {
|
||||
tagVersion, err := sv.ToVersion(tag)
|
||||
if err != nil {
|
||||
return semver.Version{}, time.Time{}, nil, fmt.Errorf("error parsing version: %s from tag, message: %v", tag, err)
|
||||
}
|
||||
func getTagVersionInfo(git sv.Git, tag string) (*semver.Version, time.Time, []sv.GitCommitLog, error) {
|
||||
tagVersion, _ := sv.ToVersion(tag)
|
||||
|
||||
previousTag, currentTag, err := getTags(git, tag)
|
||||
if err != nil {
|
||||
return semver.Version{}, time.Time{}, nil, fmt.Errorf("error listing tags, message: %v", err)
|
||||
return nil, time.Time{}, nil, fmt.Errorf("error listing tags, message: %v", err)
|
||||
}
|
||||
|
||||
commits, err := git.Log(sv.NewLogRange(sv.TagRange, previousTag, tag))
|
||||
if err != nil {
|
||||
return semver.Version{}, time.Time{}, nil, fmt.Errorf("error getting git log from tag: %s, message: %v", tag, err)
|
||||
return nil, time.Time{}, nil, fmt.Errorf("error getting git log from tag: %s, message: %v", tag, err)
|
||||
}
|
||||
|
||||
return tagVersion, currentTag.Date, commits, nil
|
||||
@ -231,20 +229,17 @@ func find(tag string, tags []sv.GitTag) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func getNextVersionInfo(git sv.Git, semverProcessor sv.SemVerCommitsProcessor) (semver.Version, bool, time.Time, []sv.GitCommitLog, error) {
|
||||
func getNextVersionInfo(git sv.Git, semverProcessor sv.SemVerCommitsProcessor) (*semver.Version, bool, time.Time, []sv.GitCommitLog, error) {
|
||||
lastTag := git.LastTag()
|
||||
|
||||
currentVer, err := sv.ToVersion(lastTag)
|
||||
if err != nil {
|
||||
return semver.Version{}, false, time.Time{}, nil, fmt.Errorf("error parsing version: %s from git tag, message: %v", lastTag, err)
|
||||
}
|
||||
|
||||
commits, err := git.Log(sv.NewLogRange(sv.TagRange, lastTag, ""))
|
||||
if err != nil {
|
||||
return semver.Version{}, false, time.Time{}, nil, fmt.Errorf("error getting git log, message: %v", err)
|
||||
return nil, false, time.Time{}, nil, fmt.Errorf("error getting git log, message: %v", err)
|
||||
}
|
||||
|
||||
currentVer, _ := sv.ToVersion(lastTag)
|
||||
version, updated := semverProcessor.NextVersion(currentVer, commits)
|
||||
|
||||
return version, updated, time.Now(), commits, nil
|
||||
}
|
||||
|
||||
@ -263,7 +258,7 @@ func tagHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor) func(c *c
|
||||
}
|
||||
|
||||
nextVer, _ := semverProcessor.NextVersion(currentVer, commits)
|
||||
tagname, err := git.Tag(nextVer)
|
||||
tagname, err := git.Tag(*nextVer)
|
||||
fmt.Println(tagname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error generating tag version: %s, message: %v", nextVer.String(), err)
|
||||
@ -417,6 +412,7 @@ func changelogHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnP
|
||||
size := c.Int("size")
|
||||
all := c.Bool("all")
|
||||
addNextVersion := c.Bool("add-next-version")
|
||||
semanticVersionOnly := c.Bool("semantic-version-only")
|
||||
|
||||
if addNextVersion {
|
||||
rnVersion, updated, date, commits, uerr := getNextVersionInfo(git, semverProcessor)
|
||||
@ -424,7 +420,7 @@ func changelogHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnP
|
||||
return uerr
|
||||
}
|
||||
if updated {
|
||||
releaseNotes = append(releaseNotes, rnProcessor.Create(&rnVersion, date, commits))
|
||||
releaseNotes = append(releaseNotes, rnProcessor.Create(rnVersion, "", date, commits))
|
||||
}
|
||||
}
|
||||
for i, tag := range tags {
|
||||
@ -437,16 +433,17 @@ func changelogHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnP
|
||||
previousTag = tags[i+1].Name
|
||||
}
|
||||
|
||||
if semanticVersionOnly && !sv.IsValidVersion(tag.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
commits, err := git.Log(sv.NewLogRange(sv.TagRange, previousTag, tag.Name))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting git log from tag: %s, message: %v", tag.Name, err)
|
||||
}
|
||||
|
||||
currentVer, err := sv.ToVersion(tag.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing version: %s from git tag, message: %v", tag.Name, err)
|
||||
}
|
||||
releaseNotes = append(releaseNotes, rnProcessor.Create(¤tVer, tag.Date, commits))
|
||||
currentVer, _ := sv.ToVersion(tag.Name)
|
||||
releaseNotes = append(releaseNotes, rnProcessor.Create(currentVer, tag.Name, tag.Date, commits))
|
||||
}
|
||||
|
||||
output, err := formatter.FormatChangelog(releaseNotes)
|
||||
|
@ -102,6 +102,7 @@ func main() {
|
||||
&cli.IntFlag{Name: "size", Value: 10, Aliases: []string{"n"}, Usage: "get changelog from last 'n' tags"},
|
||||
&cli.BoolFlag{Name: "all", Usage: "ignore size parameter, get changelog for every tag"},
|
||||
&cli.BoolFlag{Name: "add-next-version", Usage: "add next version on change log (commits since last tag, but only if there is a new version to release)"},
|
||||
&cli.BoolFlag{Name: "semantic-version-only", Usage: "only show tags 'SemVer-ish'"},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
19
go.mod
19
go.mod
@ -1,18 +1,21 @@
|
||||
module github.com/bvieira/sv4git/v2
|
||||
|
||||
go 1.16
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/Masterminds/semver/v3 v3.1.1
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
|
||||
github.com/imdario/mergo v0.3.12
|
||||
github.com/juju/ansiterm v0.0.0-20210706145210-9283cdf370b5 // indirect
|
||||
github.com/kelseyhightower/envconfig v1.4.0
|
||||
github.com/lunixbochs/vtclean v1.0.0 // indirect
|
||||
github.com/manifoldco/promptui v0.8.0
|
||||
github.com/mattn/go-colorable v0.1.8 // indirect
|
||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||
github.com/manifoldco/promptui v0.9.0
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
|
||||
github.com/kr/pretty v0.3.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
)
|
||||
|
37
go.sum
37
go.sum
@ -10,31 +10,24 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
|
||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
|
||||
github.com/juju/ansiterm v0.0.0-20210706145210-9283cdf370b5 h1:Q5klzs6BL5FkassBX65t+KkG0XjYcjxEm+GNcQAsuaw=
|
||||
github.com/juju/ansiterm v0.0.0-20210706145210-9283cdf370b5/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
|
||||
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
||||
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||
github.com/lunixbochs/vtclean v1.0.0 h1:xu2sLAri4lGiovBDQKxl5mrXyESr3gUr5m5SM5+LVb8=
|
||||
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||
github.com/manifoldco/promptui v0.8.0 h1:R95mMF+McvXZQ7j1g8ucVZE1gLP3Sv6j9vlF9kyRqQo=
|
||||
github.com/manifoldco/promptui v0.8.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
|
||||
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
|
||||
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
@ -42,13 +35,13 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type releaseNoteTemplateVariables struct {
|
||||
Version string
|
||||
Release string
|
||||
Date string
|
||||
Sections map[string]ReleaseNoteSection
|
||||
Order []string
|
||||
@ -40,7 +40,7 @@ const (
|
||||
{{- end}}
|
||||
{{- end}}`
|
||||
|
||||
rnTemplate = `## {{if .Version}}v{{.Version}}{{end}}{{if and .Date .Version}} ({{end}}{{.Date}}{{if and .Version .Date}}){{end}}
|
||||
rnTemplate = `## {{if .Release}}{{.Release}}{{end}}{{if and .Date .Release}} ({{end}}{{.Date}}{{if and .Date .Release}}){{end}}
|
||||
{{- $sections := .Sections }}
|
||||
{{- range $key := .Order }}
|
||||
{{- template "rnSection" (index $sections $key) }}
|
||||
@ -100,12 +100,14 @@ func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables
|
||||
date = releasenote.Date.Format("2006-01-02")
|
||||
}
|
||||
|
||||
version := ""
|
||||
release := ""
|
||||
if releasenote.Version != nil {
|
||||
version = releasenote.Version.String()
|
||||
release = "v" + releasenote.Version.String()
|
||||
} else if releasenote.Tag != "" {
|
||||
release = releasenote.Tag
|
||||
}
|
||||
return releaseNoteTemplateVariables{
|
||||
Version: version,
|
||||
Release: release,
|
||||
Date: date,
|
||||
Sections: releasenote.Sections,
|
||||
Order: []string{"feat", "fix", "refactor", "perf", "test", "build", "ci", "chore", "docs", "style"},
|
||||
|
@ -10,6 +10,9 @@ import (
|
||||
var dateChangelog = `## v1.0.0 (2020-05-01)
|
||||
`
|
||||
|
||||
var nonVersioningChangelog = `## abc (2020-05-01)
|
||||
`
|
||||
|
||||
var emptyDateChangelog = `## v1.0.0
|
||||
`
|
||||
|
||||
@ -47,6 +50,7 @@ func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
||||
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog, false},
|
||||
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog, false},
|
||||
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog, false},
|
||||
{"non versioning tag", emptyReleaseNote("abc", date.Truncate(time.Minute)), nonVersioningChangelog, false},
|
||||
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@ -63,27 +67,21 @@ func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func emptyReleaseNote(version string, date time.Time) ReleaseNote {
|
||||
var v *semver.Version
|
||||
if version != "" {
|
||||
v = semver.MustParse(version)
|
||||
}
|
||||
func emptyReleaseNote(tag string, date time.Time) ReleaseNote {
|
||||
v, _ := semver.NewVersion(tag)
|
||||
return ReleaseNote{
|
||||
Version: v,
|
||||
Tag: tag,
|
||||
Date: date,
|
||||
}
|
||||
}
|
||||
|
||||
func fullReleaseNote(version string, date time.Time) ReleaseNote {
|
||||
var v *semver.Version
|
||||
if version != "" {
|
||||
v = semver.MustParse(version)
|
||||
}
|
||||
|
||||
func fullReleaseNote(tag string, date time.Time) ReleaseNote {
|
||||
v, _ := semver.NewVersion(tag)
|
||||
sections := map[string]ReleaseNoteSection{
|
||||
"build": newReleaseNoteSection("Build", []GitCommitLog{commitlog("build", map[string]string{})}),
|
||||
"feat": newReleaseNoteSection("Features", []GitCommitLog{commitlog("feat", map[string]string{})}),
|
||||
"fix": newReleaseNoteSection("Bug Fixes", []GitCommitLog{commitlog("fix", map[string]string{})}),
|
||||
}
|
||||
return releaseNote(v, date, sections, []string{"break change message"})
|
||||
return releaseNote(v, tag, date, sections, []string{"break change message"})
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
"github.com/Masterminds/semver/v3"
|
||||
)
|
||||
|
||||
func version(v string) semver.Version {
|
||||
func version(v string) *semver.Version {
|
||||
r, _ := semver.NewVersion(v)
|
||||
return *r
|
||||
return r
|
||||
}
|
||||
|
||||
func commitlog(ctype string, metadata map[string]string) GitCommitLog {
|
||||
@ -26,13 +26,14 @@ func commitlog(ctype string, metadata map[string]string) GitCommitLog {
|
||||
}
|
||||
}
|
||||
|
||||
func releaseNote(version *semver.Version, date time.Time, sections map[string]ReleaseNoteSection, breakingChanges []string) ReleaseNote {
|
||||
func releaseNote(version *semver.Version, tag string, date time.Time, sections map[string]ReleaseNoteSection, breakingChanges []string) ReleaseNote {
|
||||
var bchanges BreakingChangeSection
|
||||
if len(breakingChanges) > 0 {
|
||||
bchanges = BreakingChangeSection{Name: "Breaking Changes", Messages: breakingChanges}
|
||||
}
|
||||
return ReleaseNote{
|
||||
Version: version,
|
||||
Tag: tag,
|
||||
Date: date.Truncate(time.Minute),
|
||||
Sections: sections,
|
||||
BreakingChanges: bchanges,
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
// ReleaseNoteProcessor release note processor interface.
|
||||
type ReleaseNoteProcessor interface {
|
||||
Create(version *semver.Version, date time.Time, commits []GitCommitLog) ReleaseNote
|
||||
Create(version *semver.Version, tag string, date time.Time, commits []GitCommitLog) ReleaseNote
|
||||
}
|
||||
|
||||
// ReleaseNoteProcessorImpl release note based on commit log.
|
||||
@ -22,7 +22,7 @@ func NewReleaseNoteProcessor(cfg ReleaseNotesConfig) *ReleaseNoteProcessorImpl {
|
||||
}
|
||||
|
||||
// Create create a release note based on commits.
|
||||
func (p ReleaseNoteProcessorImpl) Create(version *semver.Version, date time.Time, commits []GitCommitLog) ReleaseNote {
|
||||
func (p ReleaseNoteProcessorImpl) Create(version *semver.Version, tag string, date time.Time, commits []GitCommitLog) ReleaseNote {
|
||||
sections := make(map[string]ReleaseNoteSection)
|
||||
var breakingChanges []string
|
||||
for _, commit := range commits {
|
||||
@ -44,12 +44,13 @@ func (p ReleaseNoteProcessorImpl) Create(version *semver.Version, date time.Time
|
||||
if name, exists := p.cfg.Headers[breakingChangeMetadataKey]; exists && len(breakingChanges) > 0 {
|
||||
breakingChangeSection = BreakingChangeSection{Name: name, Messages: breakingChanges}
|
||||
}
|
||||
return ReleaseNote{Version: version, Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChangeSection}
|
||||
return ReleaseNote{Version: version, Tag: tag, Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChangeSection}
|
||||
}
|
||||
|
||||
// ReleaseNote release note.
|
||||
type ReleaseNote struct {
|
||||
Version *semver.Version
|
||||
Tag string
|
||||
Date time.Time
|
||||
Sections map[string]ReleaseNoteSection
|
||||
BreakingChanges BreakingChangeSection
|
||||
|
@ -14,6 +14,7 @@ func TestReleaseNoteProcessorImpl_Create(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
version *semver.Version
|
||||
tag string
|
||||
date time.Time
|
||||
commits []GitCommitLog
|
||||
want ReleaseNote
|
||||
@ -21,29 +22,32 @@ func TestReleaseNoteProcessorImpl_Create(t *testing.T) {
|
||||
{
|
||||
name: "mapped tag",
|
||||
version: semver.MustParse("1.0.0"),
|
||||
tag: "v1.0.0",
|
||||
date: date,
|
||||
commits: []GitCommitLog{commitlog("t1", map[string]string{})},
|
||||
want: releaseNote(semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
want: releaseNote(semver.MustParse("1.0.0"), "v1.0.0", date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
},
|
||||
{
|
||||
name: "unmapped tag",
|
||||
version: semver.MustParse("1.0.0"),
|
||||
tag: "v1.0.0",
|
||||
date: date,
|
||||
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{})},
|
||||
want: releaseNote(semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
want: releaseNote(semver.MustParse("1.0.0"), "v1.0.0", date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
},
|
||||
{
|
||||
name: "breaking changes tag",
|
||||
version: semver.MustParse("1.0.0"),
|
||||
tag: "v1.0.0",
|
||||
date: date,
|
||||
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{"breaking-change": "breaks"})},
|
||||
want: releaseNote(semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, []string{"breaks"}),
|
||||
want: releaseNote(semver.MustParse("1.0.0"), "v1.0.0", date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, []string{"breaks"}),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := NewReleaseNoteProcessor(ReleaseNotesConfig{Headers: map[string]string{"t1": "Tag 1", "t2": "Tag 2", "breaking-change": "Breaking Changes"}})
|
||||
if got := p.Create(tt.version, tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) {
|
||||
if got := p.Create(tt.version, tt.tag, tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ReleaseNoteProcessorImpl.Create() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
|
35
sv/semver.go
35
sv/semver.go
@ -11,22 +11,24 @@ const (
|
||||
major
|
||||
)
|
||||
|
||||
// IsValidVersion return true when a version is valid.
|
||||
func IsValidVersion(value string) bool {
|
||||
_, err := semver.NewVersion(value)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// ToVersion parse string to semver.Version.
|
||||
func ToVersion(value string) (semver.Version, error) {
|
||||
func ToVersion(value string) (*semver.Version, error) {
|
||||
version := value
|
||||
if version == "" {
|
||||
version = "0.0.0"
|
||||
}
|
||||
v, err := semver.NewVersion(version)
|
||||
if err != nil {
|
||||
return semver.Version{}, err
|
||||
}
|
||||
return *v, nil
|
||||
return semver.NewVersion(version)
|
||||
}
|
||||
|
||||
// SemVerCommitsProcessor interface.
|
||||
type SemVerCommitsProcessor interface {
|
||||
NextVersion(version semver.Version, commits []GitCommitLog) (semver.Version, bool)
|
||||
NextVersion(version *semver.Version, commits []GitCommitLog) (*semver.Version, bool)
|
||||
}
|
||||
|
||||
// SemVerCommitsProcessorImpl process versions using commit log.
|
||||
@ -50,7 +52,7 @@ func NewSemVerCommitsProcessor(vcfg VersioningConfig, mcfg CommitMessageConfig)
|
||||
}
|
||||
|
||||
// NextVersion calculates next version based on commit log.
|
||||
func (p SemVerCommitsProcessorImpl) NextVersion(version semver.Version, commits []GitCommitLog) (semver.Version, bool) {
|
||||
func (p SemVerCommitsProcessorImpl) NextVersion(version *semver.Version, commits []GitCommitLog) (*semver.Version, bool) {
|
||||
versionToUpdate := none
|
||||
for _, commit := range commits {
|
||||
if v := p.versionTypeToUpdate(commit); v > versionToUpdate {
|
||||
@ -58,15 +60,24 @@ func (p SemVerCommitsProcessorImpl) NextVersion(version semver.Version, commits
|
||||
}
|
||||
}
|
||||
|
||||
updated := versionToUpdate != none
|
||||
if version == nil {
|
||||
return nil, updated
|
||||
}
|
||||
newVersion := updateVersion(*version, versionToUpdate)
|
||||
return &newVersion, updated
|
||||
}
|
||||
|
||||
func updateVersion(version semver.Version, versionToUpdate versionType) semver.Version {
|
||||
switch versionToUpdate {
|
||||
case major:
|
||||
return version.IncMajor(), true
|
||||
return version.IncMajor()
|
||||
case minor:
|
||||
return version.IncMinor(), true
|
||||
return version.IncMinor()
|
||||
case patch:
|
||||
return version.IncPatch(), true
|
||||
return version.IncPatch()
|
||||
default:
|
||||
return version, false
|
||||
return version
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,16 +11,18 @@ func TestSemVerCommitsProcessorImpl_NextVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ignoreUnknown bool
|
||||
version semver.Version
|
||||
version *semver.Version
|
||||
commits []GitCommitLog
|
||||
want semver.Version
|
||||
want *semver.Version
|
||||
wantUpdated bool
|
||||
}{
|
||||
{"no update", true, version("0.0.0"), []GitCommitLog{}, version("0.0.0"), false},
|
||||
{"no update without version", true, nil, []GitCommitLog{}, nil, false},
|
||||
{"no update on unknown type", true, version("0.0.0"), []GitCommitLog{commitlog("a", map[string]string{})}, version("0.0.0"), false},
|
||||
{"no update on unmapped known type", false, version("0.0.0"), []GitCommitLog{commitlog("none", map[string]string{})}, version("0.0.0"), false},
|
||||
{"update patch on unknown type", false, version("0.0.0"), []GitCommitLog{commitlog("a", map[string]string{})}, version("0.0.1"), true},
|
||||
{"patch update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{})}, version("0.0.1"), true},
|
||||
{"patch update without version", false, nil, []GitCommitLog{commitlog("patch", map[string]string{})}, nil, true},
|
||||
{"minor update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{}), commitlog("minor", map[string]string{})}, version("0.1.0"), true},
|
||||
{"major update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{}), commitlog("major", map[string]string{})}, version("1.0.0"), true},
|
||||
{"breaking change update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{}), commitlog("patch", map[string]string{"breaking-change": "break"})}, version("1.0.0"), true},
|
||||
@ -43,11 +45,11 @@ func TestToVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want semver.Version
|
||||
want *semver.Version
|
||||
wantErr bool
|
||||
}{
|
||||
{"empty version", "", version("0.0.0"), false},
|
||||
{"invalid version", "abc", semver.Version{}, true},
|
||||
{"invalid version", "abc", nil, true},
|
||||
{"valid version", "1.2.3", version("1.2.3"), false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@ -63,3 +65,33 @@ func TestToVersion(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsValidVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value string
|
||||
want bool
|
||||
}{
|
||||
{"simple version", "1.0.0", true},
|
||||
{"with v prefix version", "v1.0.0", true},
|
||||
{"prerelease version", "1.0.0-alpha", true},
|
||||
{"prerelease version", "1.0.0-alpha.1", true},
|
||||
{"prerelease version", "1.0.0-0.3.7", true},
|
||||
{"prerelease version", "1.0.0-x.7.z.92", true},
|
||||
{"prerelease version", "1.0.0-x-y-z.-", true},
|
||||
{"metadata version", "1.0.0-alpha+001", true},
|
||||
{"metadata version", "1.0.0+20130313144700", true},
|
||||
{"metadata version", "1.0.0-beta+exp.sha.5114f85", true},
|
||||
{"metadata version", "1.0.0+21AF26D3-117B344092BD", true},
|
||||
{"incomplete version", "1", true},
|
||||
{"invalid version", "invalid", false},
|
||||
{"invalid prefix version", "random1.0.0", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IsValidVersion(tt.value); got != tt.want {
|
||||
t.Errorf("IsValidVersion(%s) = %v, want %v", tt.value, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user