CLI that turns LLM input into well-formatted Conventional Commits
0

Configure Feed

Select the types of activity you want to include in your feed.

feat: add subject validation and length checking

Add buildAndValidateSubject function to construct commit subjects in
conventional commit format and validate they don't exceed 50 characters.
Truncated subjects show exceeding portion with ellipsis in error output.

Implements: bug-5b35298
Co-authored-by: Crush <crush@charm.land>

Amolith (Oct 21, 2025, 7:23 PM -0600) 29fbff3e 672dead0

+38 -5
+38 -5
main.go
··· 6 6 7 7 import ( 8 8 "context" 9 + "fmt" 9 10 "os" 10 11 "runtime/debug" 12 + "strings" 11 13 12 14 "github.com/charmbracelet/fang" 13 15 "github.com/spf13/cobra" ··· 47 49 -b "Had to do a weird thing because..." 48 50 `, 49 51 RunE: func(cmd *cobra.Command, args []string) error { 50 - // TODO: Implement commit formatting logic here 51 - // 1. Validate subject length (type(scope): message <= 50 chars) 52 - // 2. Format body as Markdown wrapped to 72 columns 53 - // 3. Validate and format trailers 54 - // 4. Pipe result to `git commit -F -` 52 + subject, err := buildAndValidateSubject(commitType, scope, message, breakingChange) 53 + if err != nil { 54 + return err 55 + } 56 + 57 + _ = subject 55 58 56 59 return nil 57 60 }, ··· 71 74 if err := rootCmd.MarkFlagRequired("message"); err != nil { 72 75 panic(err) 73 76 } 77 + } 78 + 79 + func buildAndValidateSubject(commitType, scope, message string, breaking bool) (string, error) { 80 + var subject strings.Builder 81 + 82 + subject.WriteString(commitType) 83 + 84 + if scope != "" { 85 + subject.WriteString("(") 86 + subject.WriteString(scope) 87 + subject.WriteString(")") 88 + } 89 + 90 + if breaking { 91 + subject.WriteString("!") 92 + } 93 + 94 + subject.WriteString(": ") 95 + subject.WriteString(message) 96 + 97 + result := subject.String() 98 + length := len(result) 99 + 100 + if length > 50 { 101 + exceededBy := length - 50 102 + truncated := result[:50] + "…" 103 + return "", fmt.Errorf("subject exceeds 50 character limit by %d:\n%s", exceededBy, truncated) 104 + } 105 + 106 + return result, nil 74 107 } 75 108 76 109 func main() {