replace commit branch with refs

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2017-11-09 10:05:50 +08:00
parent 3c1cfa628f
commit 0927e34a03
3 changed files with 50 additions and 37 deletions

17
tags.go
View File

@@ -9,8 +9,8 @@ import (
// DefaultTagSuffix returns a set of default suggested tags
// based on the commit ref with an attached suffix.
func DefaultTagSuffix(ref, suffix, commitBranch, defaultBranch string) []string {
tags := DefaultTags(ref, commitBranch, defaultBranch)
func DefaultTagSuffix(ref, suffix, defaultBranch string) []string {
tags := DefaultTags(ref, defaultBranch)
if len(suffix) == 0 {
return tags
}
@@ -26,10 +26,12 @@ func DefaultTagSuffix(ref, suffix, commitBranch, defaultBranch string) []string
// DefaultTags returns a set of default suggested tags based on
// the commit ref.
func DefaultTags(ref, commitBranch, defaultBranch string) []string {
func DefaultTags(ref, defaultBranch string) []string {
if defaultBranch != "" && commitBranch != defaultBranch && !strings.HasPrefix(ref, "refs/tags/") {
return []string{}
if defaultBranch != "" && strings.HasPrefix(ref, "refs/heads/") {
if stripHeadPrefix(ref) != defaultBranch {
return []string{}
}
}
if !strings.HasPrefix(ref, "refs/tags/") {
@@ -64,3 +66,8 @@ func stripTagPrefix(ref string) string {
ref = strings.TrimPrefix(ref, "v")
return ref
}
func stripHeadPrefix(ref string) string {
ref = strings.TrimPrefix(ref, "refs/heads/")
return ref
}