(apiKey, diff, filename string, cfg config.Config, includeEmoji bool)
| 14 | var emojis = []string{"✨", "🛠️", "🐛", "🔥", "📝", "🚀", "🔧", "🎨", "🔒", "💄"} |
| 15 | |
| 16 | func GenerateCommitMessage(apiKey, diff, filename string, cfg config.Config, includeEmoji bool) string { |
| 17 | commitMsg := ai.CallGemini(apiKey, diff) |
| 18 | if commitMsg == "" { |
| 19 | commitMsg = "update " + filename |
| 20 | } |
| 21 | |
| 22 | hasPrefix := false |
| 23 | for _, p := range cfg.CommitPrefixes { |
| 24 | if strings.HasPrefix(strings.ToLower(commitMsg), strings.ToLower(p)) { |
| 25 | hasPrefix = true |
| 26 | break |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | if !hasPrefix && len(cfg.CommitPrefixes) > 0 { |
| 31 | rand.Seed(time.Now().UnixNano()) |
| 32 | prefix := cfg.CommitPrefixes[rand.Intn(len(cfg.CommitPrefixes))] |
| 33 | commitMsg = prefix + " " + commitMsg |
| 34 | } |
| 35 | |
| 36 | if includeEmoji { |
| 37 | rand.Seed(time.Now().UnixNano()) |
| 38 | emoji := emojis[rand.Intn(len(emojis))] |
| 39 | commitMsg = fmt.Sprintf("%s %s", emoji, commitMsg) |
| 40 | } |
| 41 | |
| 42 | if len(commitMsg) > cfg.MaxCommitLength { |
| 43 | commitMsg = commitMsg[:cfg.MaxCommitLength-3] + "..." |
| 44 | } |
| 45 | |
| 46 | return commitMsg |
| 47 | } |
| 48 | |
| 49 | func CommitFile(filename, commitMsg string) (string, error) { |
| 50 | cmd := exec.Command("git", "commit", "-m", commitMsg, "--", filename) |
no test coverage detected