Skip to content

Commit a8ea1f0

Browse files
committed
[ignore] simplify regex and variable setting in ParseVersion function
1 parent 5b33cc7 commit a8ea1f0

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

internal/provider/function_compare_versions.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,17 @@ type VersionResult struct {
178178
}
179179

180180
func ParseVersion(rawVersion string) VersionResult {
181-
versionRegex := regexp.MustCompile(`((\d+)\.(\d+)\((\d+)([a-z])\)|(\d+)\.(\d+)\((\d+))`)
181+
versionRegex := regexp.MustCompile(`(\d+)\.(\d+)\((\d+)([a-z]?)\)`)
182182
matches := versionRegex.FindStringSubmatch(rawVersion)
183183
if matches == nil {
184184
return VersionResult{Error: "unknown"}
185185
}
186-
major, _ := strconv.Atoi(matches[2])
187-
minor := 0
188-
patch := 0
186+
major, _ := strconv.Atoi(matches[1])
187+
minor, _ := strconv.Atoi(matches[2])
188+
patch, _ := strconv.Atoi(matches[3])
189189
tag := 0
190-
if major != 0 {
191-
minor, _ = strconv.Atoi(matches[3])
192-
patch, _ = strconv.Atoi(matches[4])
193-
tag = int(matches[5][0])
194-
} else {
195-
major, _ = strconv.Atoi(matches[6])
196-
minor, _ = strconv.Atoi(matches[7])
197-
patch, _ = strconv.Atoi(matches[8])
190+
if matches[4] != "" {
191+
tag = int(matches[4][0])
198192
}
199193

200194
return VersionResult{Version: &Version{Major: major, Minor: minor, Patch: patch, Tag: tag}}

0 commit comments

Comments
 (0)