2023-12-05 09:03:18 +00:00
|
|
|
package tag
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
2024-03-11 08:23:17 +00:00
|
|
|
// stripHeadPrefix removes the "refs/heads/" prefix from the given ref string.
|
|
|
|
// It is used to clean up Git ref names.
|
2023-12-05 09:03:18 +00:00
|
|
|
func stripHeadPrefix(ref string) string {
|
|
|
|
return strings.TrimPrefix(ref, "refs/heads/")
|
|
|
|
}
|
|
|
|
|
2024-03-11 08:23:17 +00:00
|
|
|
// stripTagPrefix removes the "refs/tags/" prefix and any "v" prefix
|
|
|
|
// from the given ref string. It is used to clean up Git tag ref names.
|
2023-12-05 09:03:18 +00:00
|
|
|
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
|
|
|
|
}
|