0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-21 22:10:39 +00:00

feat: add semantic-version-only flat to changelog command

This commit is contained in:
Beatriz Vieira 2022-01-29 19:25:52 -03:00
parent ab57089ddd
commit 6352021adb
4 changed files with 42 additions and 0 deletions

View File

@ -412,6 +412,7 @@ func changelogHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnP
size := c.Int("size") size := c.Int("size")
all := c.Bool("all") all := c.Bool("all")
addNextVersion := c.Bool("add-next-version") addNextVersion := c.Bool("add-next-version")
semanticVersionOnly := c.Bool("semantic-version-only")
if addNextVersion { if addNextVersion {
rnVersion, updated, date, commits, uerr := getNextVersionInfo(git, semverProcessor) rnVersion, updated, date, commits, uerr := getNextVersionInfo(git, semverProcessor)
@ -432,6 +433,10 @@ func changelogHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor, rnP
previousTag = tags[i+1].Name previousTag = tags[i+1].Name
} }
if semanticVersionOnly && !sv.IsValidVersion(tag.Name) {
continue
}
commits, err := git.Log(sv.NewLogRange(sv.TagRange, previousTag, tag.Name)) commits, err := git.Log(sv.NewLogRange(sv.TagRange, previousTag, tag.Name))
if err != nil { if err != nil {
return fmt.Errorf("error getting git log from tag: %s, message: %v", tag.Name, err) return fmt.Errorf("error getting git log from tag: %s, message: %v", tag.Name, err)

View File

@ -102,6 +102,7 @@ func main() {
&cli.IntFlag{Name: "size", Value: 10, Aliases: []string{"n"}, Usage: "get changelog from last 'n' tags"}, &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: "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: "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'"},
}, },
}, },
{ {

View File

@ -11,6 +11,12 @@ const (
major 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. // ToVersion parse string to semver.Version.
func ToVersion(value string) (*semver.Version, error) { func ToVersion(value string) (*semver.Version, error) {
version := value version := value

View File

@ -65,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)
}
})
}
}