Skip to content

Commit

Permalink
feat: allow user to override commit title character limit setting
Browse files Browse the repository at this point in the history
As discussed with @stefanlogue, we want to treat the 48 chars as the absolute minimum

- to avoid unintended behaviours if someone supplies a negative value
- or if the value they supply is too small for the commit type to fit in it.
  • Loading branch information
henkka authored and stefanlogue committed May 13, 2024
1 parent def68fe commit 42abf48
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
15 changes: 11 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"github.com/stefanlogue/meteor/pkg/config"
)

const defaultCommitTitleCharLimit = 48

// loadConfig loads the config file from the current directory or any parent
func loadConfig(fs afero.Fs) ([]huh.Option[string], []huh.Option[string], []huh.Option[string], bool, error) {
func loadConfig(fs afero.Fs) ([]huh.Option[string], []huh.Option[string], []huh.Option[string], bool, int, error) {
filePath, err := config.FindConfigFile(fs)
if err != nil {
log.Debug("Error finding config file", "error", err)
return config.DefaultPrefixes, nil, nil, true, nil
return config.DefaultPrefixes, nil, nil, true, defaultCommitTitleCharLimit, nil
}

log.Debug("found config file", "path", filePath)
Expand All @@ -23,13 +25,18 @@ func loadConfig(fs afero.Fs) ([]huh.Option[string], []huh.Option[string], []huh.

err = c.LoadFile(filePath)
if err != nil {
return nil, nil, nil, true, fmt.Errorf("error parsing config file: %w", err)
return nil, nil, nil, true, defaultCommitTitleCharLimit, fmt.Errorf("error parsing config file: %w", err)
}

if c.ShowIntro == nil {
showIntro := true
c.ShowIntro = &showIntro
}

return c.Prefixes.Options(), c.Coauthors.Options(), c.Boards.Options(), *c.ShowIntro, nil
if c.CommitTitleCharLimit == nil || *c.CommitTitleCharLimit < defaultCommitTitleCharLimit {
commitTitleCharLimit := defaultCommitTitleCharLimit
c.CommitTitleCharLimit = &commitTitleCharLimit
}

return c.Prefixes.Options(), c.Coauthors.Options(), c.Boards.Options(), *c.ShowIntro, *c.CommitTitleCharLimit, nil
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func main() {
fail("Could not change directory: %s", err)
}

prefixes, coauthors, boards, showIntro, err := loadConfig(AFS)
prefixes, coauthors, boards, showIntro, commitTitleCharLimit, err := loadConfig(AFS)
if err != nil {
fail("Error: %s", err)
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func main() {
huh.NewInput().
Value(&newCommit.Message).
Title("Message").
CharLimit(48),
CharLimit(commitTitleCharLimit),
huh.NewText().
Value(&newCommit.Body).
Title("Body").
Expand Down
9 changes: 5 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

type Config struct {
ShowIntro *bool `json:"showIntro"`
Prefixes Prefixes `json:"prefixes"`
Coauthors CoAuthors `json:"coauthors"`
Boards Boards `json:"boards"`
ShowIntro *bool `json:"showIntro"`
Prefixes Prefixes `json:"prefixes"`
Coauthors CoAuthors `json:"coauthors"`
Boards Boards `json:"boards"`
CommitTitleCharLimit *int `json:"commitTitleCharLimit"`
}

// New returns a new Config
Expand Down

0 comments on commit 42abf48

Please sign in to comment.