Class: CommitAI
- Inherits:
-
Object
- Object
- CommitAI
- Defined in:
- lib/commit_ai.rb
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize ⇒ CommitAI
constructor
A new instance of CommitAI.
Constructor Details
#initialize ⇒ CommitAI
Returns a new instance of CommitAI.
5 6 7 |
# File 'lib/commit_ai.rb', line 5 def initialize @client = OpenAI::Client.new(access_token: ENV['OPENAI_ACCESS_TOKEN']) end |
Instance Method Details
#execute ⇒ Object
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) = STDIN.gets.chomp.downcase = == 'y' ? 'multi' : 'single' = (diff, , user_description) loop do puts "\nGenerated Commit Message:\n#{}".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 '#{}'") puts "Commit successful!".colorize(:green) break when 'r' = (diff, , user_description) puts "Regenerating commit message...".colorize(:yellow) next when 'e' system("git commit -m '#{}' -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 |