From 3aa2ecc487ec00b0bb5847a81d3b8f6b630f2bf8 Mon Sep 17 00:00:00 2001 From: Beatriz Vieira Date: Sun, 14 Feb 2021 20:02:11 -0300 Subject: [PATCH] refactor: remove unused var envs --- cmd/git-sv/config.go | 17 +---------------- cmd/git-sv/handlers.go | 4 ++-- cmd/git-sv/main.go | 2 +- sv/config.go | 8 ++++---- sv/message.go | 8 ++++---- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/cmd/git-sv/config.go b/cmd/git-sv/config.go index a006802..eac5c58 100644 --- a/cmd/git-sv/config.go +++ b/cmd/git-sv/config.go @@ -16,26 +16,11 @@ import ( // EnvConfig env vars for cli configuration type EnvConfig struct { Home string `envconfig:"SV4GIT_HOME" default:""` - - MajorVersionTypes []string `envconfig:"MAJOR_VERSION_TYPES" default:""` - MinorVersionTypes []string `envconfig:"MINOR_VERSION_TYPES" default:"feat"` - PatchVersionTypes []string `envconfig:"PATCH_VERSION_TYPES" default:"build,ci,chore,docs,fix,perf,refactor,style,test"` - IncludeUnknownTypeAsPatch bool `envconfig:"INCLUDE_UNKNOWN_TYPE_AS_PATCH" default:"true"` - BreakingChangePrefixes []string `envconfig:"BRAKING_CHANGE_PREFIXES" default:"BREAKING CHANGE,BREAKING CHANGES"` - IssueIDPrefixes []string `envconfig:"ISSUEID_PREFIXES" default:"jira,JIRA,Jira"` - TagPattern string `envconfig:"TAG_PATTERN" default:"%d.%d.%d"` - ReleaseNotesTags map[string]string `envconfig:"RELEASE_NOTES_TAGS" default:"fix:Bug Fixes,feat:Features"` - ValidateMessageSkipBranches []string `envconfig:"VALIDATE_MESSAGE_SKIP_BRANCHES" default:"master,develop"` - CommitMessageTypes []string `envconfig:"COMMIT_MESSAGE_TYPES" default:"build,ci,chore,docs,feat,fix,perf,refactor,revert,style,test"` - IssueKeyName string `envconfig:"ISSUE_KEY_NAME" default:"jira"` - IssueRegex string `envconfig:"ISSUE_REGEX" default:"[A-Z]+-[0-9]+"` - BranchIssuePrefixRegex string `envconfig:"BRANCH_ISSUE_PREFIX_REGEX" default:"([a-z]+\\/)?"` - BranchIssueSuffixRegex string `envconfig:"BRANCH_ISSUE_SUFFIX_REGEX" default:"(-.*)?"` } func loadEnvConfig() EnvConfig { var c EnvConfig - err := envconfig.Process("SV4GIT", &c) + err := envconfig.Process("", &c) if err != nil { log.Fatal(err.Error()) } diff --git a/cmd/git-sv/handlers.go b/cmd/git-sv/handlers.go index 7ac3a24..07178c3 100644 --- a/cmd/git-sv/handlers.go +++ b/cmd/git-sv/handlers.go @@ -262,7 +262,7 @@ func tagHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor) func(c *c } } -func commitHandler(cfg EnvConfig, git sv.Git, messageProcessor sv.MessageProcessor) func(c *cli.Context) error { +func commitHandler(cfg Config, git sv.Git, messageProcessor sv.MessageProcessor) func(c *cli.Context) error { return func(c *cli.Context) error { ctype, err := promptType() @@ -297,7 +297,7 @@ func commitHandler(cfg EnvConfig, git sv.Git, messageProcessor sv.MessageProcess if err != nil { return err } - issue, err := promptIssueID(cfg.IssueKeyName, cfg.IssueRegex, branchIssue) + issue, err := promptIssueID(cfg.CommitMessage.IssueFooterConfig().Key, cfg.CommitMessage.Issue.Regex, branchIssue) if err != nil { return err } diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index ffdb0d9..c7c7c10 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -136,7 +136,7 @@ func main() { Name: "commit", Aliases: []string{"cmt"}, Usage: "execute git commit with convetional commit message helper", - Action: commitHandler(envCfg, git, messageProcessor), + Action: commitHandler(cfg, git, messageProcessor), }, { Name: "validate-commit-message", diff --git a/sv/config.go b/sv/config.go index 1e9e866..f140052 100644 --- a/sv/config.go +++ b/sv/config.go @@ -10,16 +10,16 @@ type CommitMessageConfig struct { Issue CommitMessageIssueConfig `yaml:"issue"` } -// IssueConfig config for issue. -func (c CommitMessageConfig) IssueConfig() CommitMessageFooterConfig { +// IssueFooterConfig config for issue. +func (c CommitMessageConfig) IssueFooterConfig() CommitMessageFooterConfig { if v, exists := c.Footer[issueKey]; exists { return v } return CommitMessageFooterConfig{} } -// BreakingChangeConfig config for breaking changes. -func (c CommitMessageConfig) BreakingChangeConfig() CommitMessageFooterConfig { +// BreakingChangeFooterConfig config for breaking changes. +func (c CommitMessageConfig) BreakingChangeFooterConfig() CommitMessageFooterConfig { if v, exists := c.Footer[breakingKey]; exists { return v } diff --git a/sv/message.go b/sv/message.go index 505ac7c..fed8dfd 100644 --- a/sv/message.go +++ b/sv/message.go @@ -88,7 +88,7 @@ func (p MessageProcessorImpl) Validate(message string) error { // Enhance add metadata on commit message. func (p MessageProcessorImpl) Enhance(branch string, message string) (string, error) { - if p.branchesCfg.DisableIssue || p.messageCfg.IssueConfig().Key == "" || hasIssueID(message, p.messageCfg.IssueConfig().Key) { + if p.branchesCfg.DisableIssue || p.messageCfg.IssueFooterConfig().Key == "" || hasIssueID(message, p.messageCfg.IssueFooterConfig().Key) { return "", nil //enhance disabled } @@ -100,7 +100,7 @@ func (p MessageProcessorImpl) Enhance(branch string, message string) (string, er return "", fmt.Errorf("could not find issue id using configured regex") } - footer := fmt.Sprintf("%s: %s", p.messageCfg.IssueConfig().Key, issue) + footer := fmt.Sprintf("%s: %s", p.messageCfg.IssueFooterConfig().Key, issue) if !hasFooter(message, p.messageCfg.Footer[breakingKey].Key) { return "\n" + footer, nil @@ -136,13 +136,13 @@ func (p MessageProcessorImpl) Format(msg CommitMessage) (string, string, string) var footer strings.Builder if msg.BreakingMessage() != "" { - footer.WriteString(fmt.Sprintf("%s: %s", p.messageCfg.BreakingChangeConfig().Key, msg.BreakingMessage())) + footer.WriteString(fmt.Sprintf("%s: %s", p.messageCfg.BreakingChangeFooterConfig().Key, msg.BreakingMessage())) } if issue, exists := msg.Metadata[issueKey]; exists { if footer.Len() > 0 { footer.WriteString("\n") } - footer.WriteString(fmt.Sprintf("%s: %s", p.messageCfg.IssueConfig().Key, issue)) + footer.WriteString(fmt.Sprintf("%s: %s", p.messageCfg.IssueFooterConfig().Key, issue)) } return header.String(), msg.Body, footer.String()