From 2d2bb64d3b126e8a29a0d46185a438436db770d1 Mon Sep 17 00:00:00 2001 From: Stavros Date: Sun, 22 Sep 2024 20:46:28 +0300 Subject: [PATCH] refactor: simplify major bump check --- internal/release/release.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/internal/release/release.go b/internal/release/release.go index 41acf24..844482a 100644 --- a/internal/release/release.go +++ b/internal/release/release.go @@ -14,27 +14,23 @@ import ( "runtipi-cli-go/internal/system" ) -func IsMajorBump(newVersion string, currentVersion string) (bool, error) { - newVersionMajor := strings.Split(strings.Replace(newVersion, "v", "", 1), ".")[0] - currentVersionMajor := strings.Split(strings.Replace(currentVersion, "v", "", 1), ".")[0] - - newVersionMajorInt, newVersionMajorIntErr := strconv.ParseInt(newVersionMajor, 10, 64) - - if newVersionMajorIntErr != nil { - return false, newVersionMajorIntErr +func IsMajorBump(newVersion, currentVersion string) (bool, error) { + parseMajor := func(version string) (int64, error) { + majorStr := strings.Split(strings.TrimPrefix(version, "v"), ".")[0] + return strconv.ParseInt(majorStr, 10, 64) } - currentVersionMajorInt, currentVersionMajorIntErr := strconv.ParseInt(currentVersionMajor, 10, 64) - - if currentVersionMajorIntErr != nil { - return false, currentVersionMajorIntErr + newVersionMajor, err := parseMajor(newVersion) + if err != nil { + return false, err } - if newVersionMajorInt > currentVersionMajorInt { - return true, nil + currentVersionMajor, err := parseMajor(currentVersion) + if err != nil { + return false, err } - return false, nil + return newVersionMajor > currentVersionMajor, nil } func GetLatestVersion() (string, error) {