Class: GitSme::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/git_sme/cli.rb

Instance Method Summary collapse

Instance Method Details

#analyze(repository) ⇒ Object



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
# File 'lib/git_sme/cli.rb', line 16

def analyze(repository)
  loader = GitSme::CommitLoader.new(repository, branch: options[:branch], enable_cache: options[:cache])
  unless loader.valid?
    puts "Error: #{loader.error_message}"
    return
  end

  puts "Repository: #{loader.repo.path.gsub('/.git/', '')}"

  loader_progress = ProgressBar.create(starting_at: 0, format: 'Loaded: %c (%R/s) %P%% %f |%B|')
  loader.load do |new_commit_count, processed_commit_count, all_commit_count|
    loader_progress.total = all_commit_count
    loader_progress.increment
  end

  analyzer = GitSme::CommitAnalyzer.new(loader, enable_cache: false)
  unless analyzer.valid?
    puts "Error: #{analyzer.error_message}"
    return
  end

  analyzer_progress = ProgressBar.create(starting_at: 0, total: loader.commits.size, format: 'Analyzed: %c (%R/s) %P%% %f |%B|')
  analyzer.analyze do |commit_count, total_commits|
    analyzer_progress.increment
  end

  presenter = AnalysisPresenter.new(analyzer, options[:user], options[:file])
  analyses = presenter.get_relevant_analyses(options[:results].to_i)

  puts

  if !analyses.empty?
    analyses.each do |result|
      result.each do |path, users|
        puts "#{path}: #{users.join(', ')}"
      end
    end
  else
    puts 'No data found!'
  end
end