9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/commit_ai.rb', line 9
def execute
system("git add --all")
diff = `git diff -U10 --staged`
if diff.empty?
puts "No changes to commit. No need to proceed.".colorize(:red)
return
end
puts "Please provide a brief description of the change made (optional):".colorize(:cyan)
user_description = STDIN.gets.chomp
puts "Do you want a multi-line commit message? (y/n) (optional):".colorize(:cyan)
message_style_input = STDIN.gets.chomp.downcase
message_style = message_style_input == 'y' ? 'multi' : 'single'
commit_message = generate_commit_message(diff, message_style, user_description)
loop do
puts "\nGenerated Commit Message:\n#{commit_message}".colorize(:green)
puts ""
puts "Do you want to proceed with the commit? (y/n), regenerate (r), or edit (e):".colorize(:cyan)
response = STDIN.gets.chomp
case response.downcase
when 'y'
system("git commit -m '#{commit_message}'")
puts "Commit successful!".colorize(:green)
break
when 'r'
commit_message = generate_commit_message(diff, message_style, user_description)
puts "Regenerating commit message...".colorize(:yellow)
next
when 'e'
system("git commit -m '#{commit_message}' -e")
puts "Commit successful after editing!".colorize(:green)
break
when 'n'
puts "Commit aborted. No changes committed.".colorize(:red)
break
else
puts "Invalid input. Please try again.".colorize(:red)
puts ""
next
end
end
end
|