Class: GitAuto::Commands::CommitMessageCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/git_auto/commands/commit_message_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CommitMessageCommand

Returns a new instance of CommitMessageCommand.



14
15
16
17
18
19
20
21
22
23
# File 'lib/git_auto/commands/commit_message_command.rb', line 14

def initialize(options = {})
  @options = options.dup
  @prompt = TTY::Prompt.new
  @spinner = TTY::Spinner.new("[:spinner] :message...")
  @settings = Config::Settings.new
  @git_service = Services::GitService.new
  @ai_service = Services::AIService.new(@settings)
  @history_service = Services::HistoryService.new
  @retry_count = 0
end

Instance Method Details

#executeObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/git_auto/commands/commit_message_command.rb', line 25

def execute
  # Get repository status
  status = @git_service.repository_status
  validate_repository(status)

  # Get and validate changes
  diff = @git_service.get_staged_diff
  validate_changes(diff)

  # Show diff preview if requested
  show_diff_preview(diff) if show_preview?

  # Generate commit message
  message = generate_commit_message(diff)

  # Handle the generated message
  handle_message(message, diff)
rescue StandardError => e
  puts "\n❌ Error: #{e.message}".red
  exit 1
end