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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de7ab665c77f18d08715d16d56b7f4cd0a3b7e677bdbeabb80b25e96afcc8f47
4
- data.tar.gz: f3cddebeaf3d1f479155e85a9039f47a14c7cc61d0390968c47fb0e810ca6ce7
3
+ metadata.gz: b47c936f4c64c0d4cb2fb5214d1bf28b188b1c14525d5984be2fb2a0f84fb287
4
+ data.tar.gz: 540d6f74110a1d86e1a34a366456224f56b78888ddbafc070fb5ef0594697e59
5
5
  SHA512:
6
- metadata.gz: 9576ab5271ad85fb136eab275b987787cac5bae9af6c3458563089dd4e782c92ce57b48630379ad7c8ebbd11a816a0f2d6b69d302557dc8f5e3f69b482d2b889
7
- data.tar.gz: e882ab4a80976721e87fcee2d5935021c2063ddf23c61e1cb26a45c7e8ead43da33610fb1f18cbd21fbc17d540cbdbdc7d9f52cc7641c666d589ce2fd41e15b2
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 ''
@@ -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: '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. ' \
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 (Claude)', value: 'anthropic', base_url: 'https://api.anthropic.com/v1' },
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CommitGpt
4
- VERSION = '0.3.4'
4
+ VERSION = '0.3.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commitgpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peng Zhang