forked from coop-cloud/tagcmp
Compare commits
1 Commits
a46196e32b
...
63ec2c5ff3
Author | SHA1 | Date |
---|---|---|
knoflook | 63ec2c5ff3 |
21
tagcmp.go
21
tagcmp.go
|
@ -14,8 +14,9 @@ type Tag struct {
|
||||||
MissingMinor bool // whether or not the minor semver part was left out
|
MissingMinor bool // whether or not the minor semver part was left out
|
||||||
Patch string `json:",omitempty"` // patch semver part
|
Patch string `json:",omitempty"` // patch semver part
|
||||||
MissingPatch bool // whether or not he patch semver part was left out
|
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
|
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.
|
// 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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if t.Metadata != tag.Metadata {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// ignore errors since Parse already handled
|
// ignore errors since Parse already handled
|
||||||
mj1, _ := strconv.Atoi(t.Major)
|
mj1, _ := strconv.Atoi(t.Major)
|
||||||
mj2, _ := strconv.Atoi(tag.Major)
|
mj2, _ := strconv.Atoi(tag.Major)
|
||||||
|
@ -136,6 +141,10 @@ func (t Tag) String() string {
|
||||||
repr += fmt.Sprintf("-%s", t.Suffix)
|
repr += fmt.Sprintf("-%s", t.Suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if t.Metadata != "" {
|
||||||
|
repr += fmt.Sprintf("+%s", t.Metadata)
|
||||||
|
}
|
||||||
|
|
||||||
return repr
|
return repr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,8 +326,15 @@ func Parse(tag string) (Tag, error) {
|
||||||
usesV = true
|
usesV = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var metadata string
|
||||||
|
splits := strings.Split(tag, "+")
|
||||||
|
if len(splits) > 1 {
|
||||||
|
tag = splits[0]
|
||||||
|
metadata = splits[1]
|
||||||
|
}
|
||||||
|
|
||||||
var suffix string
|
var suffix string
|
||||||
splits := strings.SplitN(tag, "-", 2)
|
splits = strings.SplitN(tag, "-", 2)
|
||||||
if len(splits) > 1 {
|
if len(splits) > 1 {
|
||||||
tag = splits[0]
|
tag = splits[0]
|
||||||
suffix = splits[1]
|
suffix = splits[1]
|
||||||
|
@ -373,6 +389,7 @@ func Parse(tag string) (Tag, error) {
|
||||||
MissingPatch: missingPatch,
|
MissingPatch: missingPatch,
|
||||||
UsesV: usesV,
|
UsesV: usesV,
|
||||||
Suffix: suffix,
|
Suffix: suffix,
|
||||||
|
Metadata: metadata,
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedTag, nil
|
return parsedTag, nil
|
||||||
|
|
Loading…
Reference in New Issue