commitgpt 0.3.4 ā 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -1
- data/lib/commitgpt/cli.rb +6 -0
- data/lib/commitgpt/commit_ai.rb +133 -10
- data/lib/commitgpt/config_manager.rb +16 -0
- data/lib/commitgpt/provider_presets.rb +1 -1
- data/lib/commitgpt/setup_wizard.rb +16 -0
- data/lib/commitgpt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b47c936f4c64c0d4cb2fb5214d1bf28b188b1c14525d5984be2fb2a0f84fb287
|
|
4
|
+
data.tar.gz: 540d6f74110a1d86e1a34a366456224f56b78888ddbafc070fb5ef0594697e59
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60c0ea07f58567bee161b6037fe6db60d92344b1098c88e33c9e4d4908ca08b36b66f722d29cc743308c1bc1f4d4c16f70fb5a7e2a65db1d8c3c0a8adafd5ef2
|
|
7
|
+
data.tar.gz: 664fa8dc1665d983485c97d064e440e434b2645ff578954d2b762ceec4a741649bb20af3c32dbd180560cd67838e6a4eee1662ef75c56b53c790216d9738f2af
|
data/README.md
CHANGED
|
@@ -155,8 +155,44 @@ $ aicm -m
|
|
|
155
155
|
$ aicm --models
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
### Choose Commit Message Format
|
|
159
|
+
Select your preferred commit message format:
|
|
160
|
+
```bash
|
|
161
|
+
$ aicm -f
|
|
162
|
+
# or
|
|
163
|
+
$ aicm --format
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
CommitGPT supports three commit message formats:
|
|
167
|
+
- **Simple** - Concise commit message (default)
|
|
168
|
+
- **Conventional** - Follow [Conventional Commits](https://www.conventionalcommits.org/) specification
|
|
169
|
+
- **Gitmoji** - Use [Gitmoji](https://gitmoji.dev/) emoji standard
|
|
170
|
+
|
|
171
|
+
Your selection will be saved in `~/.config/commitgpt/config.yml` and used for all future commits until changed.
|
|
172
|
+
|
|
173
|
+
#### Format Examples
|
|
174
|
+
|
|
175
|
+
**Simple:**
|
|
176
|
+
```
|
|
177
|
+
Add user authentication feature
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Conventional:**
|
|
181
|
+
```
|
|
182
|
+
feat: add user authentication feature
|
|
183
|
+
fix: resolve login timeout issue
|
|
184
|
+
docs: update API documentation
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Gitmoji:**
|
|
188
|
+
```
|
|
189
|
+
⨠add user authentication feature
|
|
190
|
+
š resolve login timeout issue
|
|
191
|
+
š update API documentation
|
|
192
|
+
```
|
|
193
|
+
|
|
158
194
|
### Check Configuration
|
|
159
|
-
View your current configuration (Provider, Model, Base URL, Diff Len):
|
|
195
|
+
View your current configuration (Provider, Model, Format, Base URL, Diff Len):
|
|
160
196
|
```bash
|
|
161
197
|
$ aicm help
|
|
162
198
|
```
|
data/lib/commitgpt/cli.rb
CHANGED
|
@@ -13,11 +13,14 @@ module CommitGpt
|
|
|
13
13
|
method_option :models, aliases: '-m', type: :boolean, desc: 'List/Select available models'
|
|
14
14
|
method_option :verbose, aliases: '-v', type: :boolean, desc: 'Show git diff being sent to AI'
|
|
15
15
|
method_option :provider, aliases: '-p', type: :boolean, desc: 'Switch active provider'
|
|
16
|
+
method_option :format, aliases: '-f', type: :boolean, desc: 'Choose commit message format'
|
|
16
17
|
def generate
|
|
17
18
|
if options[:provider]
|
|
18
19
|
CommitGpt::SetupWizard.new.switch_provider
|
|
19
20
|
elsif options[:models]
|
|
20
21
|
CommitGpt::SetupWizard.new.change_model
|
|
22
|
+
elsif options[:format]
|
|
23
|
+
CommitGpt::SetupWizard.new.choose_format
|
|
21
24
|
else
|
|
22
25
|
CommitGpt::CommitAi.new.aicm(verbose: options[:verbose])
|
|
23
26
|
end
|
|
@@ -38,6 +41,7 @@ module CommitGpt
|
|
|
38
41
|
shell.say 'Options:'
|
|
39
42
|
shell.say ' -m, --models # Interactive model selection'
|
|
40
43
|
shell.say ' -p, --provider # Switch active provider'
|
|
44
|
+
shell.say ' -f, --format # Choose commit message format'
|
|
41
45
|
shell.say ' -v, --verbose # Show git diff being sent to AI'
|
|
42
46
|
shell.say ''
|
|
43
47
|
|
|
@@ -52,9 +56,11 @@ module CommitGpt
|
|
|
52
56
|
shell.say "Bin Path: #{File.realpath($PROGRAM_NAME)}".gray
|
|
53
57
|
shell.say ''
|
|
54
58
|
|
|
59
|
+
format = CommitGpt::ConfigManager.get_commit_format
|
|
55
60
|
shell.say 'Current Configuration:'
|
|
56
61
|
shell.say " Provider: #{config['name'].green}"
|
|
57
62
|
shell.say " Model: #{config['model'].cyan}"
|
|
63
|
+
shell.say " Format: #{format.capitalize.yellow}"
|
|
58
64
|
shell.say " Base URL: #{config['base_url']}"
|
|
59
65
|
shell.say " Diff Len: #{config['diff_len']}"
|
|
60
66
|
shell.say ''
|
data/lib/commitgpt/commit_ai.rb
CHANGED
|
@@ -13,10 +13,109 @@ require_relative 'diff_helpers'
|
|
|
13
13
|
# CommitGpt based on GPT-3
|
|
14
14
|
module CommitGpt
|
|
15
15
|
# Commit AI roboter based on GPT-3
|
|
16
|
-
class CommitAi
|
|
16
|
+
class CommitAi # rubocop:disable Metrics/ClassLength
|
|
17
17
|
include DiffHelpers
|
|
18
18
|
|
|
19
|
-
attr_reader :api_key, :base_url, :model, :diff_len
|
|
19
|
+
attr_reader :api_key, :base_url, :model, :diff_len, :commit_format
|
|
20
|
+
|
|
21
|
+
# Commit format templates
|
|
22
|
+
COMMIT_FORMATS = {
|
|
23
|
+
'simple' => '<commit message>',
|
|
24
|
+
'conventional' => '<type>[optional (<scope>)]: <commit message>',
|
|
25
|
+
'gitmoji' => ':emoji: <commit message>'
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
# Conventional commit types based on aicommits implementation
|
|
29
|
+
CONVENTIONAL_TYPES = {
|
|
30
|
+
'docs' => 'Documentation only changes',
|
|
31
|
+
'style' => 'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
|
|
32
|
+
'refactor' => 'A code change that improves code structure without changing functionality (renaming, restructuring classes/methods, extracting functions, etc)',
|
|
33
|
+
'perf' => 'A code change that improves performance',
|
|
34
|
+
'test' => 'Adding missing tests or correcting existing tests',
|
|
35
|
+
'build' => 'Changes that affect the build system or external dependencies',
|
|
36
|
+
'ci' => 'Changes to our CI configuration files and scripts',
|
|
37
|
+
'chore' => "Other changes that don't modify src or test files",
|
|
38
|
+
'revert' => 'Reverts a previous commit',
|
|
39
|
+
'feat' => 'A new feature',
|
|
40
|
+
'fix' => 'A bug fix'
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
# Gitmoji mappings based on gitmoji.dev
|
|
44
|
+
GITMOJI_TYPES = {
|
|
45
|
+
'šØ' => 'Improve structure / format of the code',
|
|
46
|
+
'ā”' => 'Improve performance',
|
|
47
|
+
'š„' => 'Remove code or files',
|
|
48
|
+
'š' => 'Fix a bug',
|
|
49
|
+
'š' => 'Critical hotfix',
|
|
50
|
+
'āØ' => 'Introduce new features',
|
|
51
|
+
'š' => 'Add or update documentation',
|
|
52
|
+
'š' => 'Deploy stuff',
|
|
53
|
+
'š' => 'Add or update the UI and style files',
|
|
54
|
+
'š' => 'Begin a project',
|
|
55
|
+
'ā
' => 'Add, update, or pass tests',
|
|
56
|
+
'š' => 'Fix security or privacy issues',
|
|
57
|
+
'š' => 'Add or update secrets',
|
|
58
|
+
'š' => 'Release / Version tags',
|
|
59
|
+
'šØ' => 'Fix compiler / linter warnings',
|
|
60
|
+
'š§' => 'Work in progress',
|
|
61
|
+
'š' => 'Fix CI Build',
|
|
62
|
+
'ā¬ļø' => 'Downgrade dependencies',
|
|
63
|
+
'ā¬ļø' => 'Upgrade dependencies',
|
|
64
|
+
'š' => 'Pin dependencies to specific versions',
|
|
65
|
+
'š·' => 'Add or update CI build system',
|
|
66
|
+
'š' => 'Add or update analytics or track code',
|
|
67
|
+
'ā»ļø' => 'Refactor code',
|
|
68
|
+
'ā' => 'Add a dependency',
|
|
69
|
+
'ā' => 'Remove a dependency',
|
|
70
|
+
'š§' => 'Add or update configuration files',
|
|
71
|
+
'šØ' => 'Add or update development scripts',
|
|
72
|
+
'š' => 'Internationalization and localization',
|
|
73
|
+
'āļø' => 'Fix typos',
|
|
74
|
+
'š©' => 'Write bad code that needs to be improved',
|
|
75
|
+
'āŖ' => 'Revert changes',
|
|
76
|
+
'š' => 'Merge branches',
|
|
77
|
+
'š¦' => 'Add or update compiled files or packages',
|
|
78
|
+
'š½' => 'Update code due to external API changes',
|
|
79
|
+
'š' => 'Move or rename resources (e.g.: files, paths, routes)',
|
|
80
|
+
'š' => 'Add or update license',
|
|
81
|
+
'š„' => 'Introduce breaking changes',
|
|
82
|
+
'š±' => 'Add or update assets',
|
|
83
|
+
'āæ' => 'Improve accessibility',
|
|
84
|
+
'š”' => 'Add or update comments in source code',
|
|
85
|
+
'š»' => 'Write code drunkenly',
|
|
86
|
+
'š¬' => 'Add or update text and literals',
|
|
87
|
+
'š' => 'Perform database related changes',
|
|
88
|
+
'š' => 'Add or update logs',
|
|
89
|
+
'š' => 'Remove logs',
|
|
90
|
+
'š„' => 'Add or update contributor(s)',
|
|
91
|
+
'šø' => 'Improve user experience / usability',
|
|
92
|
+
'š' => 'Make architectural changes',
|
|
93
|
+
'š±' => 'Work on responsive design',
|
|
94
|
+
'š¤”' => 'Mock things',
|
|
95
|
+
'š„' => 'Add or update an easter egg',
|
|
96
|
+
'š' => 'Add or update a .gitignore file',
|
|
97
|
+
'šø' => 'Add or update snapshots',
|
|
98
|
+
'ā' => 'Perform experiments',
|
|
99
|
+
'š' => 'Improve SEO',
|
|
100
|
+
'š·' => 'Add or update types',
|
|
101
|
+
'š±' => 'Add or update seed files',
|
|
102
|
+
'š©' => 'Add, update, or remove feature flags',
|
|
103
|
+
'š„
' => 'Catch errors',
|
|
104
|
+
'š«' => 'Add or update animations and transitions',
|
|
105
|
+
'š' => 'Deprecate code that needs to be cleaned up',
|
|
106
|
+
'š' => 'Work on code related to authorization, roles and permissions',
|
|
107
|
+
'š©¹' => 'Simple fix for a non-critical issue',
|
|
108
|
+
'š§' => 'Data exploration/inspection',
|
|
109
|
+
'ā°' => 'Remove dead code',
|
|
110
|
+
'š§Ŗ' => 'Add a failing test',
|
|
111
|
+
'š' => 'Add or update business logic',
|
|
112
|
+
'š©ŗ' => 'Add or update healthcheck',
|
|
113
|
+
'š§±' => 'Infrastructure related changes',
|
|
114
|
+
'š§āš»' => 'Improve developer experience',
|
|
115
|
+
'šø' => 'Add sponsorships or money related infrastructure',
|
|
116
|
+
'š§µ' => 'Add or update code related to multithreading or concurrency',
|
|
117
|
+
'š¦ŗ' => 'Add or update code related to validation'
|
|
118
|
+
}.freeze
|
|
20
119
|
|
|
21
120
|
def initialize
|
|
22
121
|
provider_config = ConfigManager.get_active_provider_config
|
|
@@ -32,6 +131,8 @@ module CommitGpt
|
|
|
32
131
|
@model = nil
|
|
33
132
|
@diff_len = 32_768
|
|
34
133
|
end
|
|
134
|
+
|
|
135
|
+
@commit_format = ConfigManager.get_commit_format
|
|
35
136
|
end
|
|
36
137
|
|
|
37
138
|
def aicm(verbose: false)
|
|
@@ -158,21 +259,42 @@ module CommitGpt
|
|
|
158
259
|
puts 'ā² This is not a git repository'.red
|
|
159
260
|
return false
|
|
160
261
|
end
|
|
161
|
-
|
|
162
262
|
true
|
|
163
263
|
end
|
|
164
264
|
|
|
265
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
165
266
|
def generate_commit(diff = '')
|
|
267
|
+
# Build format-specific prompt
|
|
268
|
+
base_prompt = 'Generate a concise git commit message title in present tense that precisely describes the key changes in the following code diff. Focus on what was changed, not just file names. Provide only the title, no description or body.'
|
|
269
|
+
|
|
270
|
+
format_instruction = case @commit_format
|
|
271
|
+
when 'conventional'
|
|
272
|
+
"Choose a type from the type-to-description JSON below that best describes the git diff:\n#{JSON.pretty_generate(CONVENTIONAL_TYPES)}"
|
|
273
|
+
when 'gitmoji'
|
|
274
|
+
"Choose an emoji from the emoji-to-description JSON below that best describes the git diff:\n#{JSON.pretty_generate(GITMOJI_TYPES)}"
|
|
275
|
+
else
|
|
276
|
+
''
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
format_spec = "The output response must be in format:\n#{COMMIT_FORMATS[@commit_format]}"
|
|
280
|
+
|
|
281
|
+
system_content = [
|
|
282
|
+
base_prompt,
|
|
283
|
+
'Message language: English.',
|
|
284
|
+
'Rules:',
|
|
285
|
+
'- Commit message must be a maximum of 100 characters.',
|
|
286
|
+
'- Exclude anything unnecessary such as translation. Your entire response will be passed directly into git commit.',
|
|
287
|
+
'- IMPORTANT: Do not include any explanations, introductions, or additional text. Do not wrap the commit message in quotes or any other formatting. The commit message must not exceed 100 characters. Respond with ONLY the commit message text.',
|
|
288
|
+
'- Be specific: include concrete details (package names, versions, functionality) rather than generic statements.',
|
|
289
|
+
'- Return ONLY the commit message, nothing else.',
|
|
290
|
+
format_instruction,
|
|
291
|
+
format_spec
|
|
292
|
+
].reject(&:empty?).join("\n")
|
|
293
|
+
|
|
166
294
|
messages = [
|
|
167
295
|
{
|
|
168
296
|
role: 'system',
|
|
169
|
-
content:
|
|
170
|
-
"Message language: English. Rules:\n" \
|
|
171
|
-
"- Commit message must be a maximum of 100 characters.\n" \
|
|
172
|
-
"- Exclude anything unnecessary such as translation. Your entire response will be passed directly into git commit.\n" \
|
|
173
|
-
"- IMPORTANT: Do not include any explanations, introductions, or additional text. Do not wrap the commit message in quotes or any other formatting. The commit message must not exceed 100 characters. Respond with ONLY the commit message text. \n" \
|
|
174
|
-
"- Be specific: include concrete details (package names, versions, functionality) rather than generic statements. \n" \
|
|
175
|
-
'- Return ONLY the commit message, nothing else.'
|
|
297
|
+
content: system_content
|
|
176
298
|
},
|
|
177
299
|
{
|
|
178
300
|
role: 'user',
|
|
@@ -373,5 +495,6 @@ module CommitGpt
|
|
|
373
495
|
first_line = full_content.split("\n").map(&:strip).reject(&:empty?).first
|
|
374
496
|
first_line&.gsub(/\A["']|["']\z/, '') || ''
|
|
375
497
|
end
|
|
498
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
|
376
499
|
end
|
|
377
500
|
end
|
|
@@ -141,6 +141,22 @@ module CommitGpt
|
|
|
141
141
|
save_main_config(main_config)
|
|
142
142
|
end
|
|
143
143
|
|
|
144
|
+
# Get commit format configuration
|
|
145
|
+
def get_commit_format
|
|
146
|
+
return 'simple' unless config_exists?
|
|
147
|
+
|
|
148
|
+
main_config = YAML.load_file(main_config_path)
|
|
149
|
+
main_config['commit_format'] || 'simple'
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Set commit format configuration
|
|
153
|
+
def set_commit_format(format)
|
|
154
|
+
ensure_config_dir
|
|
155
|
+
main_config = config_exists? ? YAML.load_file(main_config_path) : { 'providers' => [], 'active_provider' => '' }
|
|
156
|
+
main_config['commit_format'] = format
|
|
157
|
+
save_main_config(main_config)
|
|
158
|
+
end
|
|
159
|
+
|
|
144
160
|
private
|
|
145
161
|
|
|
146
162
|
# Merge main config with local config (local overrides main)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module CommitGpt
|
|
4
4
|
# Provider presets for common AI providers
|
|
5
5
|
PROVIDER_PRESETS = [
|
|
6
|
-
{ label: 'Anthropic
|
|
6
|
+
{ label: 'Anthropic Claude', value: 'anthropic', base_url: 'https://api.anthropic.com/v1' },
|
|
7
7
|
{ label: 'Cerebras', value: 'cerebras', base_url: 'https://api.cerebras.ai/v1' },
|
|
8
8
|
{ label: 'DeepSeek', value: 'deepseek', base_url: 'https://api.deepseek.com' },
|
|
9
9
|
{ label: 'Google AI', value: 'gemini', base_url: 'https://generativelanguage.googleapis.com/v1beta/openai' },
|
|
@@ -86,6 +86,22 @@ module CommitGpt
|
|
|
86
86
|
puts "\nModel selected: #{model}".green
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
+
# Choose commit message format
|
|
90
|
+
def choose_format
|
|
91
|
+
prompt = TTY::Prompt.new
|
|
92
|
+
|
|
93
|
+
puts "\nā² Choose git commit message format:\n".green
|
|
94
|
+
|
|
95
|
+
format = prompt.select('Select format:') do |menu|
|
|
96
|
+
menu.choice 'Simple - Concise commit message', 'simple'
|
|
97
|
+
menu.choice 'Conventional - Follow Conventional Commits specification', 'conventional'
|
|
98
|
+
menu.choice 'Gitmoji - Use Gitmoji emoji standard', 'gitmoji'
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
ConfigManager.set_commit_format(format)
|
|
102
|
+
puts "\nā² Commit format set to: #{format}".green
|
|
103
|
+
end
|
|
104
|
+
|
|
89
105
|
private
|
|
90
106
|
|
|
91
107
|
# Select provider from list
|
data/lib/commitgpt/version.rb
CHANGED