chore: move tag helpers to tag package (#36)

This commit is contained in:
Robert Kaussow 2023-12-05 10:03:18 +01:00 committed by GitHub
parent 58c6aa57d6
commit 01669b9aff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 28 deletions

View File

@ -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
}

View File

@ -1,4 +1,4 @@
package plugin
package tag
import (
"reflect"

29
tag/util.go Normal file
View File

@ -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
}