mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-12 15:00:39 +00:00
Merge pull request #29 from bvieira/cli-errors
Bugfix: better logs on fatal errors
This commit is contained in:
commit
8597819cfa
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -24,7 +23,7 @@ func loadEnvConfig() EnvConfig {
|
||||
var c EnvConfig
|
||||
err := envconfig.Process("", &c)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
log.Fatal("failed to load env config, error: ", err.Error())
|
||||
}
|
||||
return c
|
||||
}
|
||||
@ -43,11 +42,16 @@ func getRepoPath() (string, error) {
|
||||
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", errors.New(string(out))
|
||||
return "", combinedOutputErr(err, out)
|
||||
}
|
||||
return strings.TrimSpace(string(out)), nil
|
||||
}
|
||||
|
||||
func combinedOutputErr(err error, out []byte) error {
|
||||
msg := strings.Split(string(out), "\n")
|
||||
return fmt.Errorf("%v - %s", err, msg[0])
|
||||
}
|
||||
|
||||
func loadConfig(filepath string) (Config, error) {
|
||||
content, rerr := ioutil.ReadFile(filepath)
|
||||
if rerr != nil {
|
||||
|
@ -27,19 +27,19 @@ func main() {
|
||||
if envCfg.Home != "" {
|
||||
if homeCfg, err := loadConfig(filepath.Join(envCfg.Home, configFilename)); err == nil {
|
||||
if merr := merge(&cfg, homeCfg); merr != nil {
|
||||
log.Fatal(merr)
|
||||
log.Fatal("failed to merge user config, error: ", merr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repoPath, rerr := getRepoPath()
|
||||
if rerr != nil {
|
||||
log.Fatal(rerr)
|
||||
log.Fatal("failed to get repository path, error: ", rerr)
|
||||
}
|
||||
|
||||
if repoCfg, err := loadConfig(filepath.Join(repoPath, repoConfigFilename)); err == nil {
|
||||
if merr := merge(&cfg, repoCfg); merr != nil {
|
||||
log.Fatal(merr)
|
||||
log.Fatal("failed to merge repo config, error: ", merr)
|
||||
}
|
||||
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten
|
||||
cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers
|
||||
@ -165,6 +165,6 @@ func main() {
|
||||
}
|
||||
|
||||
if apperr := app.Run(os.Args); apperr != nil {
|
||||
log.Fatal(apperr)
|
||||
log.Fatal("failed to run cli, error: ", apperr)
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ func (p MessageProcessorImpl) Validate(message string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateType check if commit type is valid.
|
||||
func (p MessageProcessorImpl) ValidateType(ctype string) error {
|
||||
if ctype == "" || !contains(ctype, p.messageCfg.Types) {
|
||||
return fmt.Errorf("message type should be one of [%v]", strings.Join(p.messageCfg.Types, ", "))
|
||||
@ -108,6 +109,7 @@ func (p MessageProcessorImpl) ValidateType(ctype string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateScope check if commit scope is valid.
|
||||
func (p MessageProcessorImpl) ValidateScope(scope string) error {
|
||||
if len(p.messageCfg.Scope.Values) > 0 && !contains(scope, p.messageCfg.Scope.Values) {
|
||||
return fmt.Errorf("message scope should one of [%v]", strings.Join(p.messageCfg.Scope.Values, ", "))
|
||||
@ -115,6 +117,7 @@ func (p MessageProcessorImpl) ValidateScope(scope string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateDescription check if commit description is valid.
|
||||
func (p MessageProcessorImpl) ValidateDescription(description string) error {
|
||||
if !regexp.MustCompile("^[a-z]+.*$").MatchString(description) {
|
||||
return fmt.Errorf("description [%s] should begins with lowercase letter", description)
|
||||
|
Loading…
Reference in New Issue
Block a user