Skip to content

Commit 326a986

Browse files
authored
Merge pull request #4 from Abizrh/feat/mapping-msg
🔥 feat (prompt): add scopes and adjusting prompt generation
2 parents e90d4bd + d2b98fe commit 326a986

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

lua/commit-ai/commit.lua

+3-29
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local action_state = require("telescope.actions.state")
99
local previewers = require("telescope.previewers")
1010
local telescope = require("telescope.builtin")
1111
local backends = require("commit-ai.backends.gemini")
12+
local Prompt = require("commit-ai.prompt")
1213

1314
local function query_ai(prompt, cb)
1415
backends.call_ai(prompt, function(response)
@@ -41,38 +42,11 @@ local function generate_commit_suggestions(cb)
4142
local git_conventions = config.git_conventions
4243
local format_lines = {}
4344
for _, convention in pairs(git_conventions) do
44-
table.insert(format_lines, string.format("- %s %s: %s", convention.icon, convention.prefix, convention.type))
45+
table.insert(format_lines, string.format("- %s %s (scope): %s", convention.icon, convention.prefix, convention.type))
4546
end
4647

47-
local prompt = string.format(
48-
"Analyze this git diff and generate commit messages in plain text.\n" ..
49-
"Use exactly this format without additional explanation:\n\n" ..
50-
"- <icon> <prefix>: <commit message>\n\n" ..
51-
"Options:\n%s\n\nGit diff:\n%s",
52-
table.concat(format_lines, "\n"),
53-
diff
54-
)
48+
local prompt = Prompt.default_prompt(diff, format_lines)
5549

56-
-- local prompt = string.format(
57-
-- "Analyze this git diff and generate multiple commit messages using exactly one of these formats:\n" ..
58-
-- "Format:\n" ..
59-
-- "- <icon> <prefix>: <commit message>\n\n" ..
60-
-- "Only respond with the commit messages, without any explanations.\n\n" ..
61-
-- "- %s %s: Documentation changes\n" ..
62-
-- "- %s %s: Bug fix\n" ..
63-
-- "- %s %s: New feature\n" ..
64-
-- "- %s %s: Chore\n" ..
65-
-- "- %s %s: Breaking change\n" ..
66-
-- "- %s %s: Enhancement\n\n" ..
67-
-- "Git diff:\n%s",
68-
-- git_conventions.docs.icon, git_conventions.docs.prefix,
69-
-- git_conventions.fix.icon, git_conventions.fix.prefix,
70-
-- git_conventions.feat.icon, git_conventions.feat.prefix,
71-
-- git_conventions.chore.icon, git_conventions.chore.prefix,
72-
-- git_conventions.refactor.icon, git_conventions.refactor.prefix,
73-
-- git_conventions.enhance.icon, git_conventions.enhance.prefix,
74-
-- diff
75-
-- )
7650
query_ai(prompt, cb)
7751
end
7852

lua/commit-ai/prompt.lua

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local M = {}
2+
3+
function M.default_prompt(diff, format_lines)
4+
return string.format(
5+
[[
6+
Analyze the following Git diff and suggest commit messages.
7+
8+
Follow this format exactly:
9+
- <icon> <prefix> (<scope>): <commit message>
10+
11+
Use one of the options below for <icon> and <prefix>, depending on the change type:
12+
13+
%s
14+
15+
Rules:
16+
1. Only use the above icons and prefixes.
17+
2. Use "chore" for configuration files (*.yml, *.json, *.env), CI/CD changes, build systems, or general non-code tasks.
18+
3. Use "fix" for bug fixes.
19+
4. Use "feat" ONLY for user-facing features or newly introduced functionality.
20+
5. Use "docs" for documentation-only changes, including README.md and LICENSE.
21+
6. Use "refactor" for breaking internal code changes that don’t affect functionality.
22+
7. Use "enhance" for performance improvements or minor internal enhancements.
23+
8. The scope in parentheses should reflect the affected module or file group (e.g., doctor, config, auth).
24+
9. Keep commit message short and imperative (e.g., "add config for <context>
25+
26+
Git diff:
27+
%s
28+
]],
29+
table.concat(format_lines, "\n"),
30+
diff
31+
)
32+
end
33+
34+
return M

0 commit comments

Comments
 (0)