github.com/pluralsh/plural-cli@v0.9.5/pkg/bundle/function.go (about) 1 package bundle 2 3 import ( 4 "fmt" 5 "os/exec" 6 "path" 7 "strings" 8 9 "github.com/pluralsh/plural-cli/pkg/api" 10 ) 11 12 func fetchFunction(item *api.ConfigurationItem) (interface{}, error) { 13 switch item.FunctionName { 14 case "repoUrl": 15 return repoUrl() 16 case "repoRoot": 17 return repoRoot() 18 case "repoName": 19 return repoName() 20 case "branchName": 21 return branchName() 22 } 23 24 return nil, fmt.Errorf("Unsupported function %s. Please contact the application developer.", item.FunctionName) 25 } 26 27 func repoRoot() (string, error) { 28 cmd := exec.Command("git", "rev-parse", "--show-toplevel") 29 res, err := cmd.CombinedOutput() 30 return strings.TrimSpace(string(res)), err 31 } 32 33 func repoName() (string, error) { 34 root, err := repoRoot() 35 return path.Base(root), err 36 } 37 38 func repoUrl() (string, error) { 39 cmd := exec.Command("git", "config", "--get", "remote.origin.url") 40 res, err := cmd.CombinedOutput() 41 return strings.TrimSpace(string(res)), err 42 } 43 44 func branchName() (string, error) { 45 cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") 46 res, err := cmd.CombinedOutput() 47 return strings.TrimSpace(string(res)), err 48 }