0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-25 07:30:38 +00:00

refactor: remove unused var envs

This commit is contained in:
Beatriz Vieira 2021-02-14 20:02:11 -03:00
parent e70283a0c5
commit 3aa2ecc487
5 changed files with 12 additions and 27 deletions

View File

@ -16,26 +16,11 @@ import (
// EnvConfig env vars for cli configuration // EnvConfig env vars for cli configuration
type EnvConfig struct { type EnvConfig struct {
Home string `envconfig:"SV4GIT_HOME" default:""` 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 { func loadEnvConfig() EnvConfig {
var c EnvConfig var c EnvConfig
err := envconfig.Process("SV4GIT", &c) err := envconfig.Process("", &c)
if err != nil { if err != nil {
log.Fatal(err.Error()) log.Fatal(err.Error())
} }

View File

@ -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 { return func(c *cli.Context) error {
ctype, err := promptType() ctype, err := promptType()
@ -297,7 +297,7 @@ func commitHandler(cfg EnvConfig, git sv.Git, messageProcessor sv.MessageProcess
if err != nil { if err != nil {
return err 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 { if err != nil {
return err return err
} }

View File

@ -136,7 +136,7 @@ func main() {
Name: "commit", Name: "commit",
Aliases: []string{"cmt"}, Aliases: []string{"cmt"},
Usage: "execute git commit with convetional commit message helper", Usage: "execute git commit with convetional commit message helper",
Action: commitHandler(envCfg, git, messageProcessor), Action: commitHandler(cfg, git, messageProcessor),
}, },
{ {
Name: "validate-commit-message", Name: "validate-commit-message",

View File

@ -10,16 +10,16 @@ type CommitMessageConfig struct {
Issue CommitMessageIssueConfig `yaml:"issue"` Issue CommitMessageIssueConfig `yaml:"issue"`
} }
// IssueConfig config for issue. // IssueFooterConfig config for issue.
func (c CommitMessageConfig) IssueConfig() CommitMessageFooterConfig { func (c CommitMessageConfig) IssueFooterConfig() CommitMessageFooterConfig {
if v, exists := c.Footer[issueKey]; exists { if v, exists := c.Footer[issueKey]; exists {
return v return v
} }
return CommitMessageFooterConfig{} return CommitMessageFooterConfig{}
} }
// BreakingChangeConfig config for breaking changes. // BreakingChangeFooterConfig config for breaking changes.
func (c CommitMessageConfig) BreakingChangeConfig() CommitMessageFooterConfig { func (c CommitMessageConfig) BreakingChangeFooterConfig() CommitMessageFooterConfig {
if v, exists := c.Footer[breakingKey]; exists { if v, exists := c.Footer[breakingKey]; exists {
return v return v
} }

View File

@ -88,7 +88,7 @@ func (p MessageProcessorImpl) Validate(message string) error {
// Enhance add metadata on commit message. // Enhance add metadata on commit message.
func (p MessageProcessorImpl) Enhance(branch string, message string) (string, error) { 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 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") 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) { if !hasFooter(message, p.messageCfg.Footer[breakingKey].Key) {
return "\n" + footer, nil return "\n" + footer, nil
@ -136,13 +136,13 @@ func (p MessageProcessorImpl) Format(msg CommitMessage) (string, string, string)
var footer strings.Builder var footer strings.Builder
if msg.BreakingMessage() != "" { 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 issue, exists := msg.Metadata[issueKey]; exists {
if footer.Len() > 0 { if footer.Len() > 0 {
footer.WriteString("\n") 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() return header.String(), msg.Body, footer.String()