forked from coop-cloud/tagcmp
feat: add Tag.UpgradeElement(newTag Tag) which returns a difference between two tags
This commit is contained in:
parent
2a8edd82d7
commit
5294d8d484
19
tagcmp.go
19
tagcmp.go
|
@ -166,6 +166,25 @@ func (t Tag) IsCompatible(tag Tag) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpgradeElement returns a Tag object which is the difference between an old and new tag
|
||||||
|
// It can contain negative numbers if comparing with an older tag
|
||||||
|
func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error) {
|
||||||
|
if !curTag.IsCompatible(newTag) {
|
||||||
|
return Tag{}, fmt.Errorf("%s and %s are not compatible with each other", curTag.String(), newTag.String())
|
||||||
|
}
|
||||||
|
diff := Tag{
|
||||||
|
Major: Itoa(Atoi(newTag.Major) - Atoi(curTag.Major)),
|
||||||
|
Minor: Itoa(Atoi(newTag.Minor) - Atoi(curTag.Minor)),
|
||||||
|
MissingMinor: false,
|
||||||
|
Patch: Itoa(Atoi(newTag.Patch) - Atoi(curTag.Patch)),
|
||||||
|
MissingPatch: false,
|
||||||
|
UsesV: false,
|
||||||
|
Suffix: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
return diff, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CommitHashPattern matches commit-like hash tags
|
// CommitHashPattern matches commit-like hash tags
|
||||||
var CommitHashPattern = "^[a-f0-9]{7,40}$"
|
var CommitHashPattern = "^[a-f0-9]{7,40}$"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue