(apiKey, diff, filename string, cfg config.Config, includeEmoji bool)
| 14 | |
| 15 | // fallbackEmojis is only used when the AI call fails and we can't ask it |
| 16 | // to pick an emoji that matches the commit's intent. |
| 17 | var fallbackEmojis = []string{"✨", "🛠️", "🐛", "🔥", "📝", "🚀", "🔧", "🎨", "🔒", "💄"} |
| 18 | |
| 19 | func GenerateCommitMessage(apiKey, diff, filename string, cfg config.Config, includeEmoji bool) string { |
| 20 | commitMsg := ai.CallOpenRouter(apiKey, cfg.Model, diff, includeEmoji) |
| 21 | if commitMsg == "" { |
| 22 | commitMsg = "update " + filename |
| 23 | if includeEmoji { |
| 24 | rand.Seed(time.Now().UnixNano()) |
| 25 | commitMsg = fallbackEmojis[rand.Intn(len(fallbackEmojis))] + " " + commitMsg |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | checkMsg := stripLeadingEmoji(commitMsg) |
| 30 | hasPrefix := false |
| 31 | for _, p := range cfg.CommitPrefixes { |
| 32 | if strings.HasPrefix(strings.ToLower(checkMsg), strings.ToLower(p)) { |
| 33 | hasPrefix = true |
| 34 | break |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if !hasPrefix && len(cfg.CommitPrefixes) > 0 { |
| 39 | rand.Seed(time.Now().UnixNano()) |
| 40 | prefix := cfg.CommitPrefixes[rand.Intn(len(cfg.CommitPrefixes))] |
| 41 | commitMsg = insertPrefix(commitMsg, prefix) |
| 42 | } |
| 43 | |
| 44 | if len(commitMsg) > cfg.MaxCommitLength { |
| 45 | commitMsg = commitMsg[:cfg.MaxCommitLength-3] + "..." |
| 46 | } |
| 47 | |
| 48 | return commitMsg |
| 49 | } |
| 50 |
no test coverage detected