From 63ec2c5ff37549ae8b2cf3dc26e5d5d6e6ff9d77 Mon Sep 17 00:00:00 2001 From: knoflook Date: Thu, 7 Oct 2021 12:05:40 +0200 Subject: [PATCH] feat!: add metadata to Tag object and update Parse(), Equals() and String() --- tagcmp.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tagcmp.go b/tagcmp.go index bce89e0..dec2450 100644 --- a/tagcmp.go +++ b/tagcmp.go @@ -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