forked from coop-cloud/tagcmp
fix: call strconv.Atoi() and strconv.Itoa() properly
This commit is contained in:
parent
778718caed
commit
03d2daced9
36
tagcmp.go
36
tagcmp.go
|
@ -173,12 +173,36 @@ func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error) {
|
|||
return Tag{}, fmt.Errorf("%s and %s are not compatible with each other", curTag.String(), newTag.String())
|
||||
}
|
||||
diff := curTag
|
||||
diff.Major(strconv.Itoa(strconv.Atoi(newTag.Major) - strconv.Atoi(curTag.Major)))
|
||||
curMajor, err := strconv.Atoi(curTag.Major)
|
||||
if err != nil {
|
||||
return Tag{}, err
|
||||
}
|
||||
curMinor, err := strconv.Atoi(curTag.Minor)
|
||||
if err != nil {
|
||||
return Tag{}, err
|
||||
}
|
||||
curPatch, err := strconv.Atoi(curTag.Patch)
|
||||
if err != nil {
|
||||
return Tag{}, err
|
||||
}
|
||||
newMajor, err := strconv.Atoi(newTag.Major)
|
||||
if err != nil {
|
||||
return Tag{}, err
|
||||
}
|
||||
newMinor, err := strconv.Atoi(newTag.Minor)
|
||||
if err != nil {
|
||||
return Tag{}, err
|
||||
}
|
||||
newPatch, err := strconv.Atoi(newTag.Patch)
|
||||
if err != nil {
|
||||
return Tag{}, err
|
||||
}
|
||||
diff.Major = strconv.Itoa(newMajor - curMajor)
|
||||
if !curTag.MissingMinor {
|
||||
diff.Minor(strconv.Itoa(strconv.Atoi(newTag.Minor) - strconv.Atoi(curTag.Minor)))
|
||||
diff.Minor = strconv.Itoa(newMinor - curMinor)
|
||||
}
|
||||
if !curTag.MissingPatch {
|
||||
diff.Patch(strconv.Itoa(strconv.Atoi(newTag.Patch) - strconv.Atoi(curTag.Patch)))
|
||||
diff.Patch = strconv.Itoa(newPatch - curPatch)
|
||||
}
|
||||
|
||||
return diff, nil
|
||||
|
@ -188,16 +212,16 @@ func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error) {
|
|||
// 1/-1: patch 2/-2: minor 4/-4: major 0: no change
|
||||
func UpgradeType(t Tag) int {
|
||||
var major, minor, patch int
|
||||
major = strconv.Atoi(t.Major)
|
||||
major, _ = strconv.Atoi(t.Major)
|
||||
if t.MissingMinor {
|
||||
minor = 0
|
||||
} else {
|
||||
minor = strconv.Atoi(t.Minor)
|
||||
minor, _ = strconv.Atoi(t.Minor)
|
||||
}
|
||||
if t.MissingPatch {
|
||||
patch = 0
|
||||
} else {
|
||||
patch := strconv.Atoi(t.Patch)
|
||||
patch, _ = strconv.Atoi(t.Patch)
|
||||
}
|
||||
if major > 0 {
|
||||
return 4
|
||||
|
|
Loading…
Reference in New Issue