Class: Github::Pulse::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/github/pulse/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Reporter

Returns a new instance of Reporter.



10
11
12
# File 'lib/github/pulse/reporter.rb', line 10

def initialize(report)
  @report = report
end

Instance Attribute Details

#reportObject (readonly)

Returns the value of attribute report.



8
9
10
# File 'lib/github/pulse/reporter.rb', line 8

def report
  @report
end

Instance Method Details

#generate(format: :json) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/github/pulse/reporter.rb', line 14

def generate(format: :json)
  case format
  when :json
    JSON.generate(report)
  when :pretty
    JSON.pretty_generate(report)
  else
    raise ArgumentError, "Unknown format: #{format}"
  end
end

#summaryObject



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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/github/pulse/reporter.rb', line 25

def summary
  lines = []
  lines << "GitHub Repository Activity Report"
  lines << "=" * 40
  
  if report[:metadata][:repository]
    repo = report[:metadata][:repository]
    lines << "Repository: #{repo[:full_name]}"
    lines << "Description: #{repo[:description]}" if repo[:description]
    lines << "Primary Language: #{repo[:language]}" if repo[:language]
    lines << "Stars: #{repo[:stars]} | Forks: #{repo[:forks]}"
    lines << ""
  end
  
  if report[:metadata][:period][:since] || report[:metadata][:period][:until]
    lines << "Analysis Period:"
    lines << "  From: #{report[:metadata][:period][:since] || 'Beginning'}"
    lines << "  To: #{report[:metadata][:period][:until] || 'Present'}"
    lines << ""
  end
  
  lines << "Analyzed at: #{report[:metadata][:analyzed_at]}"
  lines << ""
  
  # Commits summary
  if report[:commits].any?
    lines << "Commits by Author:"
    report[:commits].each do |author, data|
      lines << "  #{author}:"
      lines << "    Total Commits: #{data[:total_commits]}"
      lines << "    Additions: +#{data[:total_additions]}"
      lines << "    Deletions: -#{data[:total_deletions]}"
    end
    lines << ""
  end
  
  # Pull requests summary
  if report[:pull_requests].any?
    lines << "Pull Requests by Author:"
    report[:pull_requests].each do |author, data|
      lines << "  #{author}:"
      lines << "    Total PRs: #{data[:total_prs]}"
      lines << "    Merged: #{data[:merged]}"
      lines << "    Open: #{data[:open]}"
      lines << "    Closed: #{data[:closed]}"
      lines << "    Additions: +#{data[:total_additions]}"
      lines << "    Deletions: -#{data[:total_deletions]}"
    end
    lines << ""
  end
  
  # Lines of code
  if report[:lines_of_code].any?
    lines << "Current Lines of Code by Author:"
    sorted_loc = report[:lines_of_code].sort_by { |_, lines| -lines }
    total_lines = sorted_loc.sum { |_, lines| lines }
    
    sorted_loc.each do |author, line_count|
      percentage = (line_count.to_f / total_lines * 100).round(1)
      lines << "  #{author}: #{line_count} lines (#{percentage}%)"
    end
    lines << "  Total: #{total_lines} lines"
    lines << ""
  end
  
  # Commit activity summary
  if report[:commit_activity].any?
    total_commits = report[:commit_activity].values.sum
    lines << "Commit Activity:"
    lines << "  Total Commits: #{total_commits}"
    lines << "  Active Days: #{report[:commit_activity].size}"
    lines << "  Average Commits/Day: #{(total_commits.to_f / report[:commit_activity].size).round(1)}"
    lines << ""
  end
  
  lines.join("\n")
end

#to_csvObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/github/pulse/reporter.rb', line 103

def to_csv
  require "csv"
  
  CSV.generate do |csv|
    # Add headers
    csv << ["Metric", "Author", "Value", "Details"]
    
    # Add commit data
    report[:commits].each do |author, data|
      csv << ["Commits", author, data[:total_commits], "Total commits"]
      csv << ["Additions", author, data[:total_additions], "Total lines added"]
      csv << ["Deletions", author, data[:total_deletions], "Total lines deleted"]
    end
    
    # Add PR data
    report[:pull_requests].each do |author, data|
      csv << ["Pull Requests", author, data[:total_prs], "Total PRs"]
      csv << ["PR Merged", author, data[:merged], "Merged PRs"]
      csv << ["PR Open", author, data[:open], "Open PRs"]
    end
    
    # Add lines of code data
    report[:lines_of_code].each do |author, lines|
      csv << ["Lines of Code", author, lines, "Current lines in codebase"]
    end
  end
end