Class: ProjectHealth::PullRequestsReport

Inherits:
Object
  • Object
show all
Defined in:
lib/project-health/report/pull_requests.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oct, name) ⇒ PullRequestsReport

Returns a new instance of PullRequestsReport.



6
7
8
9
10
11
# File 'lib/project-health/report/pull_requests.rb', line 6

def initialize(oct, name)
  @open_times = []
  @open   = oct.pull_requests(name, :open).tap{|x| x.each(&method(:calc_open_pull_time)) }.count
  @closed = oct.pull_requests(name, :closed).count
  @all    = open + closed
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



4
5
6
# File 'lib/project-health/report/pull_requests.rb', line 4

def all
  @all
end

#closedObject (readonly)

Returns the value of attribute closed.



4
5
6
# File 'lib/project-health/report/pull_requests.rb', line 4

def closed
  @closed
end

#openObject (readonly)

Returns the value of attribute open.



4
5
6
# File 'lib/project-health/report/pull_requests.rb', line 4

def open
  @open
end

Instance Method Details

#average_open_timeObject



48
49
50
# File 'lib/project-health/report/pull_requests.rb', line 48

def average_open_time
  open_time / open if open > 0
end

#closed_percentObject



36
37
38
# File 'lib/project-health/report/pull_requests.rb', line 36

def closed_percent
  closed.percent_of all
end

#healthObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/project-health/report/pull_requests.rb', line 60

def health
  case open_closed_ratio.to_f
  when 0..0.1
    "Good"
  when 0.1..0.2
    "Normal"
  when 0.2..1
    "Bad"
  else
    "Unknown"
  end
end

#max_open_timeObject



56
57
58
# File 'lib/project-health/report/pull_requests.rb', line 56

def max_open_time
  @open_times.max
end

#min_open_timeObject



52
53
54
# File 'lib/project-health/report/pull_requests.rb', line 52

def min_open_time
  @open_times.min
end

#open_closed_ratioObject



40
41
42
# File 'lib/project-health/report/pull_requests.rb', line 40

def open_closed_ratio
  result = open_percent / closed_percent
end

#open_percentObject



32
33
34
# File 'lib/project-health/report/pull_requests.rb', line 32

def open_percent
  open.percent_of all
end

#open_timeObject



44
45
46
# File 'lib/project-health/report/pull_requests.rb', line 44

def open_time
  @open_times.inject(:+) || 0
end

#statsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/project-health/report/pull_requests.rb', line 13

def stats
  {
    "Pull Requests"=>
    {
      'All'      => all,
      'Open'     => open,
      'Closed'   => closed,
      'Open %'   => open_percent.to_f.round(2),
      'Closed %' => closed_percent.to_f.round(2),
      'Open/Closed % ratio' => open_closed_ratio.to_f.round(2),
      'Open time in days' => open_time,
      'Min open time in days' => min_open_time,
      'Max open time in days' => max_open_time,
      'Average days request is opened' => average_open_time,
      'Health' => health
    }
  }.delete_if{|k,v| v.kind_of?(Float) && v.nan?}
end