| 63 | } |
| 64 | |
| 65 | func runCommitMsg(_ *cobra.Command, _ []string) error { |
| 66 | if !allowedTypes[commitMsgType] { |
| 67 | return fmt.Errorf("invalid commit type %q (allowed: feat, fix, chore, docs, test, refactor)", commitMsgType) |
| 68 | } |
| 69 | |
| 70 | flags := GetGlobalFlags() |
| 71 | scanDir := ResolveScanDir(nil) |
| 72 | |
| 73 | taskScanner := scanner.NewScanner(scanDir, flags.Verbose, flags.IgnoreDirs) |
| 74 | result, err := taskScanner.Scan() |
| 75 | if err != nil { |
| 76 | return fmt.Errorf("scan failed: %w", err) |
| 77 | } |
| 78 | |
| 79 | tasks := result.Tasks |
| 80 | |
| 81 | warnDuplicateIDs(tasks) |
| 82 | |
| 83 | if commitMsgTaskID != "" { |
| 84 | task := findExactMatch(commitMsgTaskID, tasks) |
| 85 | if task == nil { |
| 86 | return fmt.Errorf("task not found: %s", commitMsgTaskID) |
| 87 | } |
| 88 | fmt.Print(buildCommitMessage([]*model.Task{task}, commitMsgType, commitMsgBody, commitMsgShort)) |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | changes, err := findTaskChangesFromDiff(tasks, scanDir) |
| 93 | if err != nil { |
| 94 | return err |
| 95 | } |
| 96 | if changes.IsEmpty() { |
| 97 | return fmt.Errorf("no task changes found in staged changes") |
| 98 | } |
| 99 | |
| 100 | fmt.Print(buildMessageFromChanges(changes, commitMsgType, commitMsgBody, commitMsgShort)) |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | // buildMessageFromChanges routes to the appropriate message builder based on |
| 105 | // which change categories are present. Single-category changes use dedicated |