Class: GitReviewer::AnalyzeOption

Inherits:
Object
  • Object
show all
Defined in:
lib/gitreviewer/option/analyze_option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, analyze_author, analyze_reviewer, verbose) ⇒ AnalyzeOption



15
16
17
18
19
20
21
22
# File 'lib/gitreviewer/option/analyze_option.rb', line 15

def initialize(source, target, analyze_author, analyze_reviewer, verbose)
  @source = source
  @target = target
  @analyze_author = analyze_author
  @analyze_reviewer = analyze_reviewer
  @analyzer = Analyzer.new(source, target)
  Printer.verbose = verbose
end

Instance Attribute Details

#analyze_authorObject

Returns the value of attribute analyze_author.



9
10
11
# File 'lib/gitreviewer/option/analyze_option.rb', line 9

def analyze_author
  @analyze_author
end

#analyze_reviewerObject

Returns the value of attribute analyze_reviewer.



10
11
12
# File 'lib/gitreviewer/option/analyze_option.rb', line 10

def analyze_reviewer
  @analyze_reviewer
end

#analyzerObject

Returns the value of attribute analyzer.



13
14
15
# File 'lib/gitreviewer/option/analyze_option.rb', line 13

def analyzer
  @analyzer
end

#sourceObject

Returns the value of attribute source.



7
8
9
# File 'lib/gitreviewer/option/analyze_option.rb', line 7

def source
  @source
end

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/gitreviewer/option/analyze_option.rb', line 8

def target
  @target
end

Instance Method Details

#executeObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gitreviewer/option/analyze_option.rb', line 24

def execute
  @analyzer.execute

  if analyze_author
    show_analyze_author
  end

  if analyze_reviewer
    show_analyze_reviewer
  end
end

#show_analyze_authorObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gitreviewer/option/analyze_option.rb', line 36

def show_analyze_author
  results = @analyzer.author_results.values
  if results.size <= 0
    return
  end
  results = results.sort_by { |item| item.line_count }.reverse
  total_file = results.sum { |item| item.file_count }
  total_line = results.sum { |item| item.line_count }
  output_rows = []
  results.each do |item|
    file_ratio = item.file_count.to_f / total_file.to_f * 100
    line_ratio = item.line_count.to_f / total_line.to_f * 100
    output_rows << [item.name, item.file_count, "#{file_ratio.round(2)}%", item.line_count, "#{line_ratio.round(2)}%"]
  end

  table = Terminal::Table.new do |t|
    t.title = "Relevant authors involved in code changes"
    t.headings = ["Related Author", "File Count", "File Ratio", "Line Count", "Line Ratio"]
    t.rows = output_rows
  end
  puts table
  puts "\n"
end

#show_analyze_reviewerObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gitreviewer/option/analyze_option.rb', line 60

def show_analyze_reviewer
  results = @analyzer.reviewer_results.values
  if results.size <= 0
    return
  end
  results = results.sort_by { |item| item.line_count }.reverse
  total_file = results.sum { |item| item.file_count }
  total_line = results.sum { |item| item.line_count }
  output_rows = []
  results.each do |item|
    file_ratio = item.file_count.to_f / total_file.to_f * 100
    line_ratio = item.line_count.to_f / total_line.to_f * 100
    output_rows << [item.name, item.file_count, "#{file_ratio.round(2)}%", item.line_count, "#{line_ratio.round(2)}%"]
  end

  table = Terminal::Table.new do |t|
    t.title = "Suggested reviewers for code changes"
    t.headings = ["Suggested Reviewer", "File Count", "File Ratio", "Line Count", "Line Ratio"]
    t.rows = output_rows
  end

  puts table
  puts "\n"
end