mirror of
https://github.com/thegeeklab/wp-plugin-go.git
synced 2024-11-22 10:20:39 +00:00
30 lines
619 B
Go
30 lines
619 B
Go
|
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
|
||
|
}
|