Skip to content

Commit 26a0c2b

Browse files
committed
fix: resolves #42
1 parent 993369b commit 26a0c2b

File tree

7 files changed

+70
-42
lines changed

7 files changed

+70
-42
lines changed

CHANGELOG.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,38 @@
1-
## [0.2.0] - 2024-12-15
1+
# Changelog
22

3-
### Added
4-
- New "Minimal" commit message style option for more concise commits
5-
- Display of AI model used in commit message generation for better transparency
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.2.1] - 2024-12-19
69

710
### Fixed
8-
- Improved Git staged changes detection for more reliable operation
9-
- Improved commit message validation for both minimal and conventional formats
11+
- Improve Claude AI response handling for conventional commit messages
12+
- Make system prompts more explicit to ensure consistent output format
13+
- Fixed error when displaying repository status with no staged files
14+
- Improved error handling in repository status display
15+
16+
### Changed
17+
- Update system prompts to be more strict and specific
18+
- Enhance commit message validation for Claude responses
19+
20+
## [0.2.0] - 2024-12-15
21+
22+
### Added
23+
- Support for multiple AI providers (OpenAI and Anthropic)
24+
- New commit message styles (minimal, conventional, simple)
25+
- Commit history analysis
26+
- Pattern detection for commit types and scopes
27+
- Secure API key storage with encryption
1028

1129
### Changed
12-
- Updated AI service integration to support minimal commit style across OpenAI and Claude
13-
- Improved error handling and user feedback during Git operations
30+
- Improved error messages and validation
31+
- Enhanced diff formatting and preview
32+
- Better handling of commit message generation
33+
34+
### Fixed
35+
- Various bug fixes and performance improvements
1436

1537
## [0.1.1] - 2024-12-13
1638

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
git_auto (0.1.1)
4+
git_auto (0.2.1)
55
clipboard (~> 1.3)
66
colorize (~> 1.1)
77
http (~> 5.1)

git_auto-0.2.1.gem

22 KB
Binary file not shown.

lib/git_auto/commands/commit_message_command.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def validate_repository(status)
5151
return if status[:has_staged_changes]
5252

5353
puts "ℹ️ Status:".blue
54-
puts " Branch: #{status[:branch]}"
55-
puts " Staged files: #{status[:staged_files].join(", ")}"
54+
puts " No changes staged for commit"
5655
puts "\n❌ No changes staged for commit. Use 'git add' to stage changes.".red
5756
exit 1
5857
end

lib/git_auto/commands/config_command.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,19 @@ def configure_commit_style
156156
"Simple (description only)" => "simple"
157157
})
158158

159-
@settings.set(:commit_style, style)
159+
@settings.save(commit_style: style)
160160
puts "✓ Commit style updated to #{style}".green
161161
end
162162

163163
def configure_preferences
164164
show_diff = @prompt.yes?("Show diff before committing?")
165-
@settings.set(:show_diff, show_diff)
165+
@settings.save(show_diff: show_diff)
166166
puts "✓ Show diff preference updated".green
167167
end
168168

169169
def configure_history_settings
170170
save_history = @prompt.yes?("Save commit history for analysis?")
171-
@settings.set(:save_history, save_history)
171+
@settings.save(save_history: save_history)
172172
puts "✓ History settings updated".green
173173
end
174174
end

lib/git_auto/services/ai_service.rb

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,17 @@ def generate_openai_commit_message(diff, style, scope = nil, retry_attempt = nil
216216
"6. Be descriptive but concise\n" \
217217
"7. Do not include a period at the end"
218218
when "conventional"
219-
"You are a commit message generator that MUST follow the conventional commit format: <type>(<scope>): <description>\n" \
220-
"Valid types are: #{commit_types}\n" \
221-
"Rules:\n" \
222-
"1. ALWAYS start with a type from the list above\n" \
223-
"2. ALWAYS use the exact format <type>(<scope>): <description>\n" \
224-
"3. Keep the message under 72 characters\n" \
225-
"4. Use lowercase\n" \
226-
"5. Use present tense\n" \
227-
"6. Be descriptive but concise\n" \
228-
"7. Do not include a period at the end"
219+
"You are a commit message generator that MUST follow these rules EXACTLY:\n" \
220+
"1. ONLY output a single line containing the commit message\n" \
221+
"2. Use format: <type>(<scope>): <description>\n" \
222+
"3. Valid types are: #{commit_types}\n" \
223+
"4. Keep under 72 characters\n" \
224+
"5. Use lowercase\n" \
225+
"6. Use present tense\n" \
226+
"7. Be descriptive but concise\n" \
227+
"8. No period at the end\n" \
228+
"9. NO explanations or additional text\n" \
229+
"10. NO markdown formatting"
229230
else
230231
"You are an expert in writing clear and concise git commit messages..."
231232
end
@@ -277,16 +278,17 @@ def generate_claude_commit_message(diff, style, scope = nil, retry_attempt = nil
277278
"6. Be descriptive but concise\n" \
278279
"7. Do not include a period at the end"
279280
when "conventional"
280-
"You are a commit message generator that MUST follow the conventional commit format: <type>(<scope>): <description>\n" \
281-
"Valid types are: #{commit_types}\n" \
282-
"Rules:\n" \
283-
"1. ALWAYS start with a type from the list above\n" \
284-
"2. ALWAYS use the exact format <type>(<scope>): <description>\n" \
285-
"3. Keep the message under 72 characters\n" \
286-
"4. Use lowercase\n" \
287-
"5. Use present tense\n" \
288-
"6. Be descriptive but concise\n" \
289-
"7. Do not include a period at the end"
281+
"You are a commit message generator that MUST follow these rules EXACTLY:\n" \
282+
"1. ONLY output a single line containing the commit message\n" \
283+
"2. Use format: <type>(<scope>): <description>\n" \
284+
"3. Valid types are: #{commit_types}\n" \
285+
"4. Keep under 72 characters\n" \
286+
"5. Use lowercase\n" \
287+
"6. Use present tense\n" \
288+
"7. Be descriptive but concise\n" \
289+
"8. No period at the end\n" \
290+
"9. NO explanations or additional text\n" \
291+
"10. NO markdown formatting"
290292
else
291293
"You are an expert in writing clear and concise git commit messages..."
292294
end
@@ -353,7 +355,8 @@ def handle_response(response)
353355
case response.code
354356
when 200
355357
json = JSON.parse(response.body.to_s)
356-
# puts "Debug - API Response: #{json.inspect}"
358+
puts "\nDebug - API Response: #{json.inspect}"
359+
357360
case @settings.get(:ai_provider)
358361
when "openai"
359362
message = json.dig("choices", 0, "message", "content")
@@ -362,7 +365,9 @@ def handle_response(response)
362365
raise Error, "No message content in response"
363366
end
364367

368+
# puts "Debug - OpenAI message: #{message}"
365369
message.split("\n").first.strip
370+
366371
when "claude"
367372
content = json.dig("content", 0, "text")
368373
# puts "Debug - Claude content: #{content.inspect}"
@@ -372,14 +377,16 @@ def handle_response(response)
372377
raise Error, "No message content in response"
373378
end
374379

375-
lines = content.split("\n").map(&:strip).reject(&:empty?)
376-
# puts "Debug - Lines: #{lines.inspect}"
380+
# Extract the first actual commit message from the response
381+
commit_message = content.scan(/(?:feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(?:\([^)]+\))?:.*/)&.first
377382

378-
message = lines.first
379-
380-
raise Error, "No valid commit message found in response" if message.nil? || !message.match?(/^[a-z]+:/)
383+
if commit_message.nil?
384+
# puts "Debug - No valid commit message pattern found in content"
385+
raise Error, "No valid commit message found in response"
386+
end
381387

382-
message
388+
# puts "Debug - Extracted commit message: #{commit_message}"
389+
commit_message.strip
383390
end
384391
when 401
385392
raise APIKeyError, "Invalid API key" unless ENV["RACK_ENV"] == "test"

lib/git_auto/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module GitAuto
4-
VERSION = "0.2.0"
4+
VERSION = "0.2.1"
55
end

0 commit comments

Comments
 (0)