feat!: add metadata to Tag object and update Parse(), Equals() and String()

This commit is contained in:
knoflook 2021-10-07 12:05:40 +02:00
parent 4249d925c8
commit 63ec2c5ff3
Signed by: knoflook
GPG Key ID: D6A1D0E8FC4FEF1C
1 changed files with 19 additions and 2 deletions

View File

@ -14,8 +14,9 @@ type Tag struct {
MissingMinor bool // whether or not the minor semver part was left out
Patch string `json:",omitempty"` // patch semver part
MissingPatch bool // whether or not he patch semver part was left out
Suffix string // tag suffix (e.g. "-alpine")
Suffix string // tag suffix (e.g. "-alpine") [would be release candidate in semver]
UsesV bool // whether or not the tag uses the "v" prefix
Metadata string // metadata: what's after + and after the first "-"
}
// ByTagAsc sorts tags in ascending order where the last element is the latest tag.
@ -96,6 +97,10 @@ func (t Tag) Equals(tag Tag) bool {
return false
}
if t.Metadata != tag.Metadata {
return false
}
// ignore errors since Parse already handled
mj1, _ := strconv.Atoi(t.Major)
mj2, _ := strconv.Atoi(tag.Major)
@ -136,6 +141,10 @@ func (t Tag) String() string {
repr += fmt.Sprintf("-%s", t.Suffix)
}
if t.Metadata != "" {
repr += fmt.Sprintf("+%s", t.Metadata)
}
return repr
}
@ -317,8 +326,15 @@ func Parse(tag string) (Tag, error) {
usesV = true
}
var metadata string
splits := strings.Split(tag, "+")
if len(splits) > 1 {
tag = splits[0]
metadata = splits[1]
}
var suffix string
splits := strings.SplitN(tag, "-", 2)
splits = strings.SplitN(tag, "-", 2)
if len(splits) > 1 {
tag = splits[0]
suffix = splits[1]
@ -373,6 +389,7 @@ func Parse(tag string) (Tag, error) {
MissingPatch: missingPatch,
UsesV: usesV,
Suffix: suffix,
Metadata: metadata,
}
return parsedTag, nil