|
| 1 | +local locales = require('commit-ai.locales') |
| 2 | +local _plugin |
| 3 | + |
| 4 | +local function get_plugin() |
| 5 | + if not _plugin then |
| 6 | + _plugin = require('commit-ai') |
| 7 | + end |
| 8 | + return _plugin |
| 9 | +end |
| 10 | + |
1 | 11 | local M = {} |
2 | 12 |
|
3 | 13 | 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 | | -Choose an appropriate <icon> and <prefix> from the list below based on the type of change: |
12 | | -
|
13 | | -%s |
14 | | -
|
15 | | -Commit 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> should desribe the affected module or file group or folder. |
24 | | -9. Keep commit message should be concise and written in the imperative mood (e.g., "add config for <context> |
25 | | -10. Only use lowercase letters in the commit message. |
26 | | -
|
27 | | -Git diff: |
28 | | -%s |
29 | | -]], |
30 | | - table.concat(format_lines, "\n"), |
31 | | - diff |
32 | | - ) |
| 14 | + local config = get_plugin().config |
| 15 | + |
| 16 | + local header = table.concat({ |
| 17 | + "Analyze the following Git diff and suggest commit messages.", |
| 18 | + "", |
| 19 | + "Follow this format exactly:", |
| 20 | + "- <icon> <prefix> (<scope>): <commit message>", |
| 21 | + "", |
| 22 | + "Commit rules:", |
| 23 | + "0. Use " .. locales[config.language] .. " for commit messages.", |
| 24 | + "1. Only use the above icons and prefixes.", |
| 25 | + "2. Use \"chore\" for configuration files (*.yml, *.json, *.env), CI/CD changes, build systems, or general non-code tasks.", |
| 26 | + "3. Use \"fix\" for bug fixes.", |
| 27 | + "4. Use \"feat\" ONLY for user-facing features or newly introduced functionality.", |
| 28 | + "5. Use \"docs\" for documentation-only changes, including README.md and LICENSE.", |
| 29 | + "6. Use \"refactor\" for breaking internal code changes that don’t affect functionality.", |
| 30 | + "7. Use \"enhance\" for performance improvements or minor internal enhancements.", |
| 31 | + "8. The <scope> should describe the affected module, file group or folder.", |
| 32 | + "9. Keep commit message concise and written in the imperative mood.", |
| 33 | + "10. Only use lowercase letters in the commit message.", |
| 34 | + "", |
| 35 | + }, "\n") |
| 36 | + |
| 37 | + local conventions_block = table.concat(format_lines, "\n") |
| 38 | + |
| 39 | + local diff_block = "\n\nGit diff:\n" .. diff |
| 40 | + |
| 41 | + local lang_name = locales[config.language] or locales.en |
| 42 | + |
| 43 | + local footer = ("\n\nLanguage: %s\n\n" .. |
| 44 | + "Please provide the commit message in the format specified above."):format(lang_name) |
| 45 | + |
| 46 | + return header |
| 47 | + .. conventions_block |
| 48 | + .. diff_block |
| 49 | + .. footer |
33 | 50 | end |
34 | 51 |
|
35 | 52 | return M |
0 commit comments