Class: Ace::GitCommit::Organisms::CommitOrchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git_commit/organisms/commit_orchestrator.rb

Overview

CommitOrchestrator coordinates the entire commit process

Constant Summary collapse

DEFAULT_SCOPE_NAME =

Reference the default scope name constant

Ace::Support::Config::Models::ConfigGroup::DEFAULT_SCOPE_NAME

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ CommitOrchestrator

Returns a new instance of CommitOrchestrator.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ace/git_commit/organisms/commit_orchestrator.rb', line 10

def initialize(config = nil)
  @config = config || load_config
  @git = Atoms::GitExecutor.new
  @diff_analyzer = Molecules::DiffAnalyzer.new(@git)
  @file_stager = Molecules::FileStager.new(@git)
  @path_resolver = Molecules::PathResolver.new(@git)
  @message_generator = Molecules::MessageGenerator.new(@config)
  @commit_grouper = Molecules::CommitGrouper.new
  @split_commit_executor = Molecules::SplitCommitExecutor.new(
    git_executor: @git,
    diff_analyzer: @diff_analyzer,
    file_stager: @file_stager,
    message_generator: @message_generator
  )
end

Instance Method Details

#execute(options) ⇒ Boolean

Execute the commit process

Parameters:

Returns:

  • (Boolean)

    True if successful



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
64
65
66
67
68
69
70
71
# File 'lib/ace/git_commit/organisms/commit_orchestrator.rb', line 29

def execute(options)
  validate_repository!

  if options.debug
    puts "Debug: Commit options:"
    options.to_h.each { |k, v| puts "  #{k}: #{v.inspect}" }
  end

  # Stage files if needed
  staging_result = stage_changes(options)

  # Stop if staging failed
  unless staging_result
    puts "\nCannot proceed with commit due to staging failure" unless options.quiet
    return false
  end

  # Ensure we have changes to commit
  has_staged_changes = @git.has_staged_changes?
  unless has_staged_changes
    puts "No changes to commit" unless options.quiet
    return true
  end
  puts "✓ Changes staged successfully" if options.stage_all? && !options.quiet

  staged_files = @file_stager.staged_files
  groups = @commit_grouper.group(staged_files, project_root: @git.repository_root)

  if options.no_split
    message = get_commit_message(options, config_override: @config)
    return handle_single_commit(message, options)
  end

  if groups.length > 1
    display_split_summary(groups) unless options.quiet
    result = @split_commit_executor.execute(groups, options)
    return result.success?
  end

  group_config = groups.first ? groups.first.config : @config
  message = get_commit_message(options, config_override: group_config)
  handle_single_commit(message, options)
end