Skip to content

Commit 4388fb7

Browse files
authored
Merge pull request #102 from muandane/fix/commits-struct
fix 🐛(cmd): add spacing between scope and commit type
2 parents d0b91a3 + 75aa1d0 commit 4388fb7

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

cmd/root.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,25 @@ func init() {
8282
}
8383

8484
func constructCommitMessage(cfg *config.Config, typeFlag, scopeFlag, messageFlag string) string {
85-
typeMatch := typeFlag
85+
typeMatch := typeFlag // Default to the raw typeFlag
8686
for _, t := range cfg.Types {
8787
if typeFlag == t.Name {
8888
if !cfg.NoEmoji {
89-
typeMatch = fmt.Sprintf("%s %s", t.Name, t.Emoji)
89+
typeMatch = fmt.Sprintf("%s %s", t.Emoji, t.Name)
90+
break
91+
} else {
92+
typeMatch = t.Name
93+
break
9094
}
91-
break
9295
}
9396
}
9497

98+
commitHeader := typeMatch
9599
if scopeFlag != "" {
96-
return fmt.Sprintf("%s(%s): %s", typeMatch, scopeFlag, messageFlag)
100+
commitHeader += fmt.Sprintf("(%s)", scopeFlag)
97101
}
98-
return fmt.Sprintf("%s: %s", typeMatch, messageFlag)
102+
103+
return fmt.Sprintf("%s: %s", commitHeader, messageFlag)
99104
}
100105

101106
// commit executes a git commit with the given message and body.

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
)
77

88
// main is the entry point of the Go program.
9-
//
109
// It calls the Execute function from the cmd package to execute the command.
1110
func main() {
1211
cmd.Execute()

pkg/utils/askQuestions.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ func AskQuestions(config *config.Config, presetType, presetMessage string) ([]st
9494

9595
commitMessage := commitType
9696
if commitScope != "" {
97-
commitMessage += fmt.Sprintf("(%s)", commitScope)
97+
commitMessage += fmt.Sprintf(" (%s)", strings.TrimSpace(commitScope))
9898
}
99-
commitMessage += fmt.Sprintf(": %s", commitSubject)
99+
commitMessage += fmt.Sprintf(": %s", strings.TrimSpace(commitSubject))
100100

101-
return []string{commitMessage, commitDescription}, nil
101+
commitBody := strings.TrimSpace(commitDescription)
102+
103+
return []string{commitMessage, commitBody}, nil
102104
}

0 commit comments

Comments
 (0)