Class: Aidp::Analyze::RubyMaatIntegration

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/analyze/ruby_maat_integration.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_dir = Dir.pwd) ⇒ RubyMaatIntegration

Returns a new instance of RubyMaatIntegration.



10
11
12
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 10

def initialize(project_dir = Dir.pwd)
  @project_dir = project_dir
end

Instance Method Details

#analyze_authorship(git_log_file = nil) ⇒ Object

Run RubyMaat analysis for authorship



50
51
52
53
54
55
56
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 50

def analyze_authorship(git_log_file = nil)
  git_log_file ||= File.join(@project_dir, "git.log")
  output_file = File.join(@project_dir, "authorship.csv")

  run_ruby_maat("authorship", git_log_file, output_file)
  parse_authorship_results(output_file)
end

#analyze_churn(git_log_file = nil) ⇒ Object

Run RubyMaat analysis for code churn



32
33
34
35
36
37
38
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 32

def analyze_churn(git_log_file = nil)
  git_log_file ||= File.join(@project_dir, "git.log")
  output_file = File.join(@project_dir, "churn.csv")

  run_ruby_maat("churn", git_log_file, output_file)
  parse_churn_results(output_file)
end

#analyze_coupling(git_log_file = nil) ⇒ Object

Run RubyMaat analysis for coupling



41
42
43
44
45
46
47
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 41

def analyze_coupling(git_log_file = nil)
  git_log_file ||= File.join(@project_dir, "git.log")
  output_file = File.join(@project_dir, "coupling.csv")

  run_ruby_maat("coupling", git_log_file, output_file)
  parse_coupling_results(output_file)
end

#analyze_summary(git_log_file = nil) ⇒ Object

Run RubyMaat analysis for summary



59
60
61
62
63
64
65
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 59

def analyze_summary(git_log_file = nil)
  git_log_file ||= File.join(@project_dir, "git.log")
  output_file = File.join(@project_dir, "summary.csv")

  run_ruby_maat("summary", git_log_file, output_file)
  parse_summary_results(output_file)
end

#generate_git_log(output_file = nil) ⇒ Object

Generate Git log for RubyMaat analysis



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 17

def generate_git_log(output_file = nil)
  output_file ||= File.join(@project_dir, "git.log")

  raise "Not a Git repository. RubyMaat requires a Git repository for analysis." unless git_repository?

  cmd = TTY::Command.new(printer: :null)
  result = cmd.run("git", "log", '--pretty=format:"%h|%an|%ad|%aE|%s"', "--date=short", "--numstat", chdir: @project_dir)

  raise "Failed to generate Git log: #{result.err}" unless result.success?

  File.write(output_file, result.out)
  output_file
end

#get_high_churn_files(threshold = 10) ⇒ Object

Get high-churn files for prioritization



127
128
129
130
131
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 127

def get_high_churn_files(threshold = 10)
  churn_data = analyze_churn
  churn_data[:files].select { |file| file[:changes] > threshold }
    .sort_by { |file| -file[:changes] }
end

#get_knowledge_silosObject

Get knowledge silos (files with single author)



141
142
143
144
145
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 141

def get_knowledge_silos
  authorship_data = analyze_authorship
  authorship_data[:files].select { |file| file[:authors].length == 1 }
    .sort_by { |file| -file[:changes] }
end

#get_tightly_coupled_files(threshold = 5) ⇒ Object

Get tightly coupled files



134
135
136
137
138
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 134

def get_tightly_coupled_files(threshold = 5)
  coupling_data = analyze_coupling
  coupling_data[:couplings].select { |coupling| coupling[:shared_changes] > threshold }
    .sort_by { |coupling| -coupling[:shared_changes] }
end

#run_chunked_analysis(git_log_file) ⇒ Object

Run analysis on large repositories using chunking



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 82

def run_chunked_analysis(git_log_file)
  puts "Large repository detected. Running chunked analysis..."

  # Split analysis into chunks
  chunks = create_analysis_chunks(git_log_file)

  results = {
    churn: {files: [], total_files: 0, total_changes: 0},
    coupling: {couplings: [], total_couplings: 0, average_coupling: 0},
    authorship: {files: [], total_files: 0, files_with_multiple_authors: 0, files_with_single_author: 0},
    summary: {summary: {}}
  }

  chunks.each_with_index do |chunk, index|
    puts "Processing chunk #{index + 1}/#{chunks.length}..."

    chunk_results = analyze_chunk(chunk)

    # Merge results
    merge_analysis_results(results, chunk_results)
  end

  # Generate consolidated report
  generate_consolidated_report(results)

  results
end

#run_comprehensive_analysisObject

Run comprehensive RubyMaat analysis



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 68

def run_comprehensive_analysis
  # Generate Git log if not exists
  git_log_file = File.join(@project_dir, "git.log")
  generate_git_log(git_log_file) unless File.exist?(git_log_file)

  # Check if repository is large and needs chunking
  if large_repository?(git_log_file)
    run_chunked_analysis(git_log_file)
  else
    run_full_analysis(git_log_file)
  end
end

#run_full_analysis(git_log_file) ⇒ Object

Run full analysis on smaller repositories



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/aidp/analyze/ruby_maat_integration.rb', line 111

def run_full_analysis(git_log_file)
  # Run all analyses
  results = {
    churn: analyze_churn(git_log_file),
    coupling: analyze_coupling(git_log_file),
    authorship: analyze_authorship(git_log_file),
    summary: analyze_summary(git_log_file)
  }

  # Generate consolidated report
  generate_consolidated_report(results)

  results
end