MCPcopy Index your code
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

14var emojis = []string{"✨", "🛠️", "🐛", "🔥", "📝", "🚀", "🔧", "🎨", "🔒", "💄"}
15
16func 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
49func CommitFile(filename, commitMsg string) (string, error) {
50 cmd := exec.Command("git", "commit", "-m", commitMsg, "--", filename)

Callers 2

processNextFileFunction · 0.92
handleReviewInputFunction · 0.92

Calls 1

CallGeminiFunction · 0.92

Tested by

no test coverage detected