MCPcopy Create free account
hub / github.com/LunaSource/Luna / GenerateCommitMessage

Function GenerateCommitMessage

git/commit.go:16–47  ·  view source on GitHub ↗
(apiKey, diff, filename string, cfg config.Config, includeEmoji bool)

Source from the content-addressed store, hash-verified

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.
17var fallbackEmojis = []string{"✨", "🛠️", "🐛", "🔥", "📝", "🚀", "🔧", "🎨", "🔒", "💄"}
18
19func 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

Callers 2

processNextFileFunction · 0.92
handleReviewInputFunction · 0.92

Calls 1

CallGeminiFunction · 0.92

Tested by

no test coverage detected