Skip to content

Commit f7c0ee6

Browse files
author
Rodrigo Navarro
committed
v2 (feature): Add BRANCH_NAME variable to templates
1 parent e066b38 commit f7c0ee6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pkg/git/git.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"os/exec"
9+
"strings"
910

1011
color "github.com/logrusorgru/aurora"
1112
)
@@ -57,3 +58,14 @@ func Amend(message string) (err error) {
5758

5859
return
5960
}
61+
62+
// BranchName return current branch name
63+
func BranchName() string {
64+
cmdGit := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
65+
branchName, err := cmdGit.Output()
66+
if err != nil {
67+
return ""
68+
}
69+
70+
return strings.TrimSuffix(string(branchName), "\n")
71+
}

pkg/template/template.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"prompt"
77
"strings"
88

9+
"git"
10+
911
color "github.com/logrusorgru/aurora"
1012
"github.com/spf13/viper"
1113
)
@@ -55,10 +57,17 @@ func executeFlow(settings map[string]interface{}) (variables []keyValue) {
5557

5658
if value, ok := pr["DEFAULT_VALUE"]; ok {
5759
defaultValue = value.(string)
60+
defaultValue = strings.Replace(defaultValue, "{{BRANCH_NAME}}", git.BranchName(), -1)
5861
}
5962

6063
if options := pr["OPTIONS"]; options == nil {
61-
result = prompt.Input(label, errorMessage, defaultValue)
64+
var labelMessage = label
65+
66+
if defaultValue != "" {
67+
labelMessage = label + " (" + defaultValue + ")"
68+
}
69+
70+
result = prompt.Input(labelMessage+":", errorMessage, defaultValue)
6271
} else {
6372
configurationSelectOption := &prompt.SelectConfiguration{
6473
ActiveTpl: "\U0001F449 {{ .Title | cyan | bold }}",

0 commit comments

Comments
 (0)