feat: add UpgradeType function which simplifies what difference is there between two tags

This commit is contained in:
knoflook 2021-10-01 20:23:48 +02:00
parent aa81b0306c
commit 72eabea81d
Signed by: knoflook
GPG Key ID: D6A1D0E8FC4FEF1C
1 changed files with 36 additions and 0 deletions

View File

@ -184,6 +184,42 @@ func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error) {
return diff, nil
}
// UpgradeType takes exit from UpgradeElemene and returns a numeric representation of upgrade or downgrade
// 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)
if t.MissingMinor {
minor = 0
} else {
minor = strconv.Atoi(t.Minor)
}
if t.MissingPatch {
patch = 0
} else {
patch := strconv.Atoi(t.Patch)
}
if major > 0 {
return 4
}
if major < 0 {
return -4
}
if minor > 0 {
return 2
}
if minor < 0 {
return -2
}
if patch > 0 {
return 1
}
if patch < 0 {
return -1
}
return 0
}
// CommitHashPattern matches commit-like hash tags
var CommitHashPattern = "^[a-f0-9]{7,40}$"