Skip to content

Commit

Permalink
feat: add 'findAllCommitMessages' configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
usrme committed Jul 25, 2023
1 parent c83bcbb commit 9e070f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ There is an additional `comet.json` file that includes the prefixes and descript

There is also a `-m` flag that takes a string that will be used as the basis for a search among all commit messages. For example: if you're committing something of a chore and always just use the message "update dependencies", you can do `cometary -m update` (use quotation marks if argument to `-m` includes spaces) and Cometary will populate the list of possible messages with those that include "update", which can then be cycled through with the Tab key. This is similar to the search you could make with `git log --grep="update"`.

By default the `-m` flag behavior is set to only populate with possible messages that adhere to conventional commits, but this behavior can be changed by setting the `findAllCommitMessages` value in the configuration file as `true`.

## Acknowledgments

Couldn't have been possible without the work of [Liam Galvin](https://github.com/liamg).
Expand Down
13 changes: 7 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ type prefix struct {
}

type config struct {
Prefixes []prefix `json:"prefixes"`
SignOffCommits bool `json:"signOffCommits"`
ScopeInputCharLimit int `json:"scopeInputCharLimit"`
CommitInputCharLimit int `json:"commitInputCharLimit"`
TotalInputCharLimit int `json:"totalInputCharLimit"`
ScopeCompletionOrder string `json:"scopeCompletionOrder"`
Prefixes []prefix `json:"prefixes"`
SignOffCommits bool `json:"signOffCommits"`
ScopeInputCharLimit int `json:"scopeInputCharLimit"`
CommitInputCharLimit int `json:"commitInputCharLimit"`
TotalInputCharLimit int `json:"totalInputCharLimit"`
ScopeCompletionOrder string `json:"scopeCompletionOrder"`
FindAllCommitMessages bool `json:"findAllCommitMessages"`
}

func (i prefix) Title() string { return i.T }
Expand Down
24 changes: 14 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
}
}

uniqueMessages := formUniqueMessages(commitMessages)
uniqueMessages := formUniqueMessages(commitMessages, config.FindAllCommitMessages)
uniquePaths := formUniquePaths(changedFiles, config.ScopeCompletionOrder)
m := newModel(prefixes, config, uniquePaths, uniqueMessages)
if _, err := tea.NewProgram(m).Run(); err != nil {
Expand All @@ -71,18 +71,22 @@ func fail(format string, args ...interface{}) {
os.Exit(1)
}

func formUniqueMessages(messages []string) []string {
func formUniqueMessages(messages []string, findAllCommitMessages bool) []string {
uniqueMap := make(map[string]bool)
var msg string
for _, m := range messages {
// Given conventional commit adherence, the semicolon can be assumed
// to be a safe enough delimiter upon which to separate prefix, an
// optional scope, and the message
s := strings.Split(m, ":")
// If m does not contain colon then it's not a valid conventional commit
if len(s) == 1 {
continue
if !findAllCommitMessages {
// Given conventional commit adherence, the semicolon can be assumed
// to be a safe enough delimiter upon which to separate prefix, an
// optional scope, and the message
s := strings.Split(m, ":")
// If m does not contain colon then it's not a valid conventional commit
if len(s) == 1 {
continue
}
msg = strings.TrimSpace(s[1])
}
msg := strings.TrimSpace(s[1])
msg = m
if _, ok := uniqueMap[msg]; ok {
continue
}
Expand Down

0 comments on commit 9e070f2

Please sign in to comment.