diff --git a/plugin/tags.go b/tag/semver.go similarity index 71% rename from plugin/tags.go rename to tag/semver.go index 157a2cb..9101b83 100644 --- a/plugin/tags.go +++ b/tag/semver.go @@ -1,4 +1,4 @@ -package plugin +package tag import ( "fmt" @@ -72,29 +72,3 @@ func SemverTags(ref string, strict bool) ([]string, error) { fmt.Sprintf("%v.%v.%v", version.Major(), version.Minor(), version.Patch()), }, nil } - -// IsTaggable checks whether tags should be created for the specified ref. -// The function returns true if the ref either matches the default branch -// or is a tag ref. -func IsTaggable(ref, defaultBranch string) bool { - if strings.HasPrefix(ref, "refs/tags/") { - return true - } - - if stripHeadPrefix(ref) == defaultBranch { - return true - } - - return false -} - -func stripHeadPrefix(ref string) string { - return strings.TrimPrefix(ref, "refs/heads/") -} - -func stripTagPrefix(ref string) string { - ref = strings.TrimPrefix(ref, "refs/tags/") - ref = strings.TrimPrefix(ref, "v") - - return ref -} diff --git a/plugin/tags_test.go b/tag/semver_test.go similarity index 99% rename from plugin/tags_test.go rename to tag/semver_test.go index 299e424..7833faf 100644 --- a/plugin/tags_test.go +++ b/tag/semver_test.go @@ -1,4 +1,4 @@ -package plugin +package tag import ( "reflect" diff --git a/tag/util.go b/tag/util.go new file mode 100644 index 0000000..83ef05b --- /dev/null +++ b/tag/util.go @@ -0,0 +1,29 @@ +package tag + +import "strings" + +func stripHeadPrefix(ref string) string { + return strings.TrimPrefix(ref, "refs/heads/") +} + +func stripTagPrefix(ref string) string { + ref = strings.TrimPrefix(ref, "refs/tags/") + ref = strings.TrimPrefix(ref, "v") + + return ref +} + +// IsTaggable checks whether tags should be created for the specified ref. +// The function returns true if the ref either matches the default branch +// or is a tag ref. +func IsTaggable(ref, defaultBranch string) bool { + if strings.HasPrefix(ref, "refs/tags/") { + return true + } + + if stripHeadPrefix(ref) == defaultBranch { + return true + } + + return false +}