forked from coop-cloud/tagcmp
feat: add UpgradeType function which simplifies what difference is there between two tags
This commit is contained in:
parent
aa81b0306c
commit
72eabea81d
36
tagcmp.go
36
tagcmp.go
|
@ -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}$"
|
||||
|
||||
|
|
Loading…
Reference in New Issue