mirror of
https://github.com/thegeeklab/wp-plugin-go.git
synced 2024-11-23 06:40:40 +00:00
chore: move tag helpers to tag package (#36)
This commit is contained in:
parent
58c6aa57d6
commit
01669b9aff
@ -1,4 +1,4 @@
|
|||||||
package plugin
|
package tag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -72,29 +72,3 @@ func SemverTags(ref string, strict bool) ([]string, error) {
|
|||||||
fmt.Sprintf("%v.%v.%v", version.Major(), version.Minor(), version.Patch()),
|
fmt.Sprintf("%v.%v.%v", version.Major(), version.Minor(), version.Patch()),
|
||||||
}, nil
|
}, 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
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package plugin
|
package tag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
29
tag/util.go
Normal file
29
tag/util.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user