mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-09 16:00:40 +00:00
feat: add semantic-version-only flat to changelog command
This commit is contained in:
parent
ab57089ddd
commit
6352021adb
@ -412,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)
|
||||
@ -432,6 +433,10 @@ 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)
|
||||
|
@ -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'"},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -11,6 +11,12 @@ 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) {
|
||||
version := value
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user