Module: AIGit

Defined in:
lib/ai_git.rb,
lib/ai_git/git.rb,
lib/ai_git/ollama.rb,
lib/ai_git/version.rb

Defined Under Namespace

Modules: Git, Ollama

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.runObject



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
# File 'lib/ai_git.rb', line 9

def run
  staged = AIGit::Git.staged_files
  abort 'Error: No staged files. Use `git add` first.' if staged.to_s.strip.empty?

  diff = AIGit::Git.diff
  branch = AIGit::Git.current_branch

  puts "\e[1mStaged Files:\e[0m #{staged}"
  puts "\e[1mBranch:\e[0m #{branch}"
  puts "\e[1mAI Generating Commit Message\e[0m"

  result = Benchmark.measure do
    message = AIGit::Ollama.generate_commit_message(diff)
    message = message.gsub(/\n{2,}/, "\n")

    puts "\e[1mCommit Message:\e[0m\n\n#{message}\n"

    escaped_msg = message.gsub(/[\\"`$]/) { |c| "\\#{c}" }
    AIGit::Git.run_command('git', "commit -m \"#{escaped_msg}\"")
    puts "\e[1mGit Commited\e[0m"

    AIGit::Git.run_command('git', 'push')
    puts "\e[1mGit Pushed\e[0m"
  end

  puts "\e[1mBenchmark\e[0m"
  puts result
end