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 8 |
# File 'lib/commit_ai.rb', line 5 def initialize @client = OpenAI::Client.new(access_token: ENV['OPENAI_ACCESS_TOKEN']) @enabled_pretext = ENV['COMMIT_AI_ENABLED_PRETEXT'] == '1' end |
Instance Method Details
#execute ⇒ Object
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 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/commit_ai.rb', line 10 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 if @enabled_pretext puts "Please provide a pretext for the commit message (optional):".colorize(:cyan) pretext = STDIN.gets.chomp 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 if @enabled_pretext puts "\nGenerated Commit Message:\n#{pretext}: #{}".colorize(:green) else puts "\nGenerated Commit Message:\n#{}".colorize(:green) end 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(@enabled_pretext ? "git commit -m '#{pretext}: #{}'" : "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 |