From e67ae6c85973e473a493dfdda65c066161f9b121 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sun, 14 Feb 2021 20:31:18 -0300 Subject: [PATCH] feat: use configured commit types on commit comand --- cmd/git-sv/handlers.go | 2 +- cmd/git-sv/prompt.go | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/cmd/git-sv/handlers.go b/cmd/git-sv/handlers.go index fcb6b87..6f4a1f0 100644 --- a/cmd/git-sv/handlers.go +++ b/cmd/git-sv/handlers.go @@ -265,7 +265,7 @@ func tagHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor) func(c *c func commitHandler(cfg Config, git sv.Git, messageProcessor sv.MessageProcessor) func(c *cli.Context) error { return func(c *cli.Context) error { - ctype, err := promptType() + ctype, err := promptType(cfg.CommitMessage.Types) if err != nil { return err } diff --git a/cmd/git-sv/prompt.go b/cmd/git-sv/prompt.go index 9f008fd..b43166e 100644 --- a/cmd/git-sv/prompt.go +++ b/cmd/git-sv/prompt.go @@ -14,18 +14,28 @@ type commitType struct { Example string } -func promptType() (commitType, error) { - items := []commitType{ - {Type: "build", Description: "changes that affect the build system or external dependencies", Example: "gradle, maven, go mod, npm"}, - {Type: "ci", Description: "changes to our CI configuration files and scripts", Example: "Circle, BrowserStack, SauceLabs"}, - {Type: "chore", Description: "update something without impacting the user", Example: "gitignore"}, - {Type: "docs", Description: "documentation only changes"}, - {Type: "feat", Description: "a new feature"}, - {Type: "fix", Description: "a bug fix"}, - {Type: "perf", Description: "a code change that improves performance"}, - {Type: "refactor", Description: "a code change that neither fixes a bug nor adds a feature"}, - {Type: "style", Description: "changes that do not affect the meaning of the code", Example: "white-space, formatting, missing semi-colons, etc"}, - {Type: "test", Description: "adding missing tests or correcting existing tests"}, +func promptType(types []string) (commitType, error) { + defaultTypes := map[string]commitType{ + "build": {Type: "build", Description: "changes that affect the build system or external dependencies", Example: "gradle, maven, go mod, npm"}, + "ci": {Type: "ci", Description: "changes to our CI configuration files and scripts", Example: "Circle, BrowserStack, SauceLabs"}, + "chore": {Type: "chore", Description: "update something without impacting the user", Example: "gitignore"}, + "docs": {Type: "docs", Description: "documentation only changes"}, + "feat": {Type: "feat", Description: "a new feature"}, + "fix": {Type: "fix", Description: "a bug fix"}, + "perf": {Type: "perf", Description: "a code change that improves performance"}, + "refactor": {Type: "refactor", Description: "a code change that neither fixes a bug nor adds a feature"}, + "style": {Type: "style", Description: "changes that do not affect the meaning of the code", Example: "white-space, formatting, missing semi-colons, etc"}, + "test": {Type: "test", Description: "adding missing tests or correcting existing tests"}, + "revert": {Type: "revert", Description: "revert a single commit"}, + } + + var items []commitType + for _, t := range types { + if v, exists := defaultTypes[t]; exists { + items = append(items, v) + } else { + items = append(items, commitType{Type: t}) + } } template := &promptui.SelectTemplates{