From 10ec6f18c4506423f32b283ecbb3f589f2ab4eb7 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sat, 31 Jul 2021 18:19:57 -0300 Subject: [PATCH 1/2] refactor: fix lint golint uncommented exported method --- sv/message.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sv/message.go b/sv/message.go index 6def635..47adec8 100644 --- a/sv/message.go +++ b/sv/message.go @@ -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) From 721e39feb12fa0684a180170c9c56e9c9e039ded Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sat, 31 Jul 2021 18:20:56 -0300 Subject: [PATCH 2/2] fix: add better logs on fatal errors --- cmd/git-sv/config.go | 10 +++++++--- cmd/git-sv/main.go | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/git-sv/config.go b/cmd/git-sv/config.go index b9d9b26..a7ed36f 100644 --- a/cmd/git-sv/config.go +++ b/cmd/git-sv/config.go @@ -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 { diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index a78fded..f446991 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -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) } }