From 9c54d0dd133419f7db55b36e95f690634913638e Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Tue, 12 Feb 2019 19:49:22 +0800 Subject: [PATCH] feat(version): support 18.06.0 tag format. Signed-off-by: Bo-Yi Wu --- go.sum | 1 + tags.go | 25 ++++++++++++++++++++----- tags_test.go | 9 +++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/go.sum b/go.sum index 1c09484..258e8ed 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ github.com/aws/aws-sdk-go v1.16.15 h1:kQyxfRyjAwIYjf0225sn/pn+WAlncKyI8dmT3+ItMFE= github.com/aws/aws-sdk-go v1.16.15/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/bradrydzewski/cli v0.0.0-20190108225652-0d51abd87c77 h1:bXc5tB7PFVzIHUfTECDt0Orw6mIAzHePWBmemvtnfiU= github.com/bradrydzewski/cli v0.0.0-20190108225652-0d51abd87c77/go.mod h1:4SmsVk3pOgYeJlG54e23Ztd/HucXeH5RmH5bNO+uOpk= github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= diff --git a/tags.go b/tags.go index 99c7a83..8972fcc 100644 --- a/tags.go +++ b/tags.go @@ -24,6 +24,16 @@ func DefaultTagSuffix(ref, suffix string) []string { return tags } +func splitOff(input string, delim string) string { + parts := strings.SplitN(input, delim, 2) + + if len(parts) == 2 { + return parts[0] + } + + return input +} + // DefaultTags returns a set of default suggested tags based on // the commit ref. func DefaultTags(ref string) []string { @@ -40,16 +50,21 @@ func DefaultTags(ref string) []string { version.String(), } } + + v = stripTagPrefix(ref) + v = splitOff(splitOff(v, "+"), "-") + dotParts := strings.SplitN(v, ".", 3) + if version.Major == 0 { return []string{ - fmt.Sprintf("%d.%d", version.Major, version.Minor), - fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch), + fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor), + fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch), } } return []string{ - fmt.Sprint(version.Major), - fmt.Sprintf("%d.%d", version.Major, version.Minor), - fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch), + fmt.Sprintf("%0*d", len(dotParts[0]), version.Major), + fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor), + fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch), } } diff --git a/tags_test.go b/tags_test.go index a68bfa5..49838d5 100644 --- a/tags_test.go +++ b/tags_test.go @@ -93,6 +93,15 @@ func TestDefaultTagSuffix(t *testing.T) { "1.9.2-nanoserver", }, }, + { + Before: "refs/tags/v18.06.0", + Suffix: "nanoserver", + After: []string{ + "18-nanoserver", + "18.06-nanoserver", + "18.06.0-nanoserver", + }, + }, } for _, test := range tests {