Resolve issue with not parsing strict ( issue#13 )

This commit is contained in:
2022-02-10 16:01:30 +00:00
parent 93ea4e6365
commit 559ed4ff59
4 changed files with 17 additions and 5 deletions
+9 -3
View File
@@ -55,6 +55,7 @@ type Force struct {
Major int
Commit string
Existing bool
Strict bool
}
type SemVer struct {
@@ -115,9 +116,14 @@ func debugPrint(content string) {
var extractNumber = regexp.MustCompile("[0-9]+")
func parseExistingSemver(tagName string) (semanticVersion SemVer) {
func parseExistingSemver(tagName string, currentSemver SemVer) (semanticVersion SemVer) {
debugPrint(fmt.Sprintln("Parsing existing semver:", tagName))
var tagNameParts []string
tagNameParts = strings.Split(tagName, ".")
if len(tagNameParts) < 3 {
debugPrint("Unable to parse incompatible semver ( non x.y.z )")
return currentSemver
}
semanticVersion.Major, _ = strconv.Atoi(extractNumber.FindAllString(tagNameParts[0], -1)[0])
semanticVersion.Minor, _ = strconv.Atoi(extractNumber.FindAllString(tagNameParts[1], -1)[0])
semanticVersion.Patch, _ = strconv.Atoi(extractNumber.FindAllString(tagNameParts[2], -1)[0])
@@ -134,7 +140,7 @@ func (s *Setup) CalculateSemver() SemVer {
for _, tagHash := range s.Tags {
if commit.Hash == tagHash.Hash {
debugPrint(fmt.Sprintln("Found existing tag:", tagHash.Name, "related to", commit.Message))
s.Semver = parseExistingSemver(tagHash.Name)
s.Semver = parseExistingSemver(tagHash.Name, s.Semver)
continue
}
}
@@ -330,7 +336,7 @@ func main() {
os.Exit(1)
}
repo.ListCommits()
if params.varExisting {
if params.varExisting || repo.Force.Existing {
repo.ListExistingTags()
}
repo.ForcedVersioning()
+5 -1
View File
@@ -569,7 +569,11 @@ func (suite *Tests) Test_parseExistingSemver() {
}
for _, tt := range tests {
suite.T().Run(tt.name, func(t *testing.T) {
got := parseExistingSemver(tt.args.tagName)
got := parseExistingSemver(tt.args.tagName, SemVer{
Major: 1,
Minor: 1,
Patch: 1,
})
assert.Equal(tt.wantSemanticVersion.Major, got.Major, "Unexpected MAJOR semver result in "+tt.name)
assert.Equal(tt.wantSemanticVersion.Minor, got.Minor, "Unexpected MINOR semver result in "+tt.name)
assert.Equal(tt.wantSemanticVersion.Patch, got.Patch, "Unexpected PATCH semver result in "+tt.name)