Skip to content

Commit

Permalink
refactor: simplify major bump check
Browse files Browse the repository at this point in the history
  • Loading branch information
steveiliop56 committed Sep 22, 2024
1 parent 023c247 commit 2d2bb64
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions internal/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2d2bb64

Please sign in to comment.