project-health 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -76,7 +76,7 @@ require 'pp'
76
76
  require 'project-health'
77
77
 
78
78
  # Set GitHub username/password to increase API rates
79
- ProjectHealth.config do |c|
79
+ ProjectHealth.configure do |c|
80
80
  #c.login = '' # use your github name
81
81
  #c.password = '' # use your github password
82
82
  end
data/bin/project-health CHANGED
@@ -15,11 +15,6 @@ end
15
15
 
16
16
  def show_project_stats(repo)
17
17
  extend Hirb::Console
18
-
19
- ProjectHealth.config do |c|
20
- c.login = ENV["GITHUB_USERNAME"]
21
- c.password = ENV["GITHUB_PASSWORD"]
22
- end
23
18
  project = ProjectHealth.new(repo)
24
19
  puts "Project Health Version: #{ProjectHealth::VERSION}"
25
20
  puts
@@ -50,7 +45,7 @@ rescue Interrupt
50
45
  `stty icanon echo`
51
46
  puts "Command cancelled."
52
47
  rescue => error
53
- puts error
48
+ p error
54
49
  exit(1)
55
50
  end
56
51
 
@@ -6,7 +6,10 @@ require 'project-health/project'
6
6
  module ProjectHealth
7
7
  class << self
8
8
  def new(*args)
9
- ProjectHealth::Project.new(*args)
9
+ Project.new(*args)
10
+ end
11
+ def configure(&block)
12
+ Project.configure(&block)
10
13
  end
11
14
  end
12
15
  end
@@ -8,6 +8,10 @@ class Numeric
8
8
  end
9
9
 
10
10
  module ProjectHealth
11
- include ActiveSupport::Configurable
12
- config_accessor :login, :password
11
+ class Project
12
+ include ActiveSupport::Configurable
13
+ config_accessor :login, :password
14
+ self.login = ENV["GITHUB_USERNAME"]
15
+ self.password = ENV["GITHUB_PASSWORD"]
16
+ end
13
17
  end
@@ -4,13 +4,14 @@ module ProjectHealth
4
4
  attr_reader :name
5
5
 
6
6
  def initialize(name)
7
- @oct = Octokit::Client.new(:auto_traversal => true,
8
- :per_page => 500, :login => ProjectHealth.config.login,
9
- :password=> ProjectHealth.config.password)
7
+ @oct = Octokit::Client.new(auto_traversal: true,
8
+ per_page: 500, login: config.login,
9
+ password: config.password)
10
10
  @name = name
11
11
  @reports = []
12
12
  add_report :basic
13
13
  add_report :pull_requests
14
+ add_report :issues
14
15
  end
15
16
 
16
17
  def add_report(report)
@@ -0,0 +1,78 @@
1
+ module ProjectHealth
2
+ class IssuesReport
3
+
4
+ attr_reader :open, :closed, :all
5
+
6
+ def initialize(oct, name)
7
+ @open_times = []
8
+ @open = oct.issues(name, {state: :open}).tap{|x| x.each(&method(:calc_open_issue_time)) }.count
9
+ @closed = oct.issues(name, {state: :closed}).count
10
+ @all = open + closed
11
+ end
12
+
13
+ def stats
14
+ {
15
+ "Issues"=>
16
+ {
17
+ 'All' => all,
18
+ 'Open' => open,
19
+ 'Closed' => closed,
20
+ 'Open %' => open_percent.to_f.round(2),
21
+ 'Closed %' => closed_percent.to_f.round(2),
22
+ 'Open/Closed % ratio' => open_closed_ratio.to_f.round(2),
23
+ 'Open time in days' => open_time,
24
+ 'Min open time in days' => min_open_time,
25
+ 'Max open time in days' => max_open_time,
26
+ 'Average days issue is opened' => average_open_time,
27
+ 'Health' => health
28
+ }
29
+ }.delete_if{|k,v| v.kind_of?(Float) && v.nan?}
30
+ end
31
+
32
+ def open_percent
33
+ open.percent_of all
34
+ end
35
+
36
+ def closed_percent
37
+ closed.percent_of all
38
+ end
39
+
40
+ def open_closed_ratio
41
+ result = open_percent / closed_percent
42
+ end
43
+
44
+ def open_time
45
+ @open_times.inject(:+) || 0
46
+ end
47
+
48
+ def average_open_time
49
+ open_time / open if open > 0
50
+ end
51
+
52
+ def min_open_time
53
+ @open_times.min
54
+ end
55
+
56
+ def max_open_time
57
+ @open_times.max
58
+ end
59
+
60
+ def health
61
+ case open_closed_ratio.to_f
62
+ when 0..0.1
63
+ "Good"
64
+ when 0.1..0.2
65
+ "Normal"
66
+ when 0.2..1
67
+ "Bad"
68
+ else
69
+ "Unknown"
70
+ end
71
+ end
72
+
73
+ private
74
+ def calc_open_issue_time(issue)
75
+ @open_times << (DateTime.now.to_i - issue.created_at.to_datetime.to_i)/60/60/24
76
+ end
77
+ end
78
+ end
@@ -1,64 +1,64 @@
1
1
  module ProjectHealth
2
2
  class PullRequestsReport
3
3
 
4
- attr_reader :pulls_open, :pulls_closed, :pulls_all
4
+ attr_reader :open, :closed, :all
5
5
 
6
6
  def initialize(oct, name)
7
- @pull_open_time = []
8
- @pulls_open = oct.pull_requests(name, :open).tap{|x| x.each(&method(:calc_open_pull_time)) }.count
9
- @pulls_closed = oct.pull_requests(name, :closed).count
10
- @pulls_all = pulls_open + pulls_closed
7
+ @open_times = []
8
+ @open = oct.pull_requests(name, :open).tap{|x| x.each(&method(:calc_open_pull_time)) }.count
9
+ @closed = oct.pull_requests(name, :closed).count
10
+ @all = open + closed
11
11
  end
12
12
 
13
13
  def stats
14
14
  {
15
15
  "Pull Requests"=>
16
16
  {
17
- 'All' => pulls_all,
18
- 'Open' => pulls_open,
19
- 'Closed' => pulls_closed,
20
- 'Open %' => pulls_open_percent.to_f.round(2),
21
- 'Closed %' => pulls_closed_percent.to_f.round(2),
22
- 'Open/Closed % ratio' => open_closed_pull_ratio.to_f.round(2),
23
- 'Open time in days' => pull_open_time,
24
- 'Min open time in days' => pull_min_open_time,
25
- 'Max open time in days' => pull_max_open_time,
26
- 'Average days request is opened' => pull_average_open_time,
27
- 'Health' => pulls_health
17
+ 'All' => all,
18
+ 'Open' => open,
19
+ 'Closed' => closed,
20
+ 'Open %' => open_percent.to_f.round(2),
21
+ 'Closed %' => closed_percent.to_f.round(2),
22
+ 'Open/Closed % ratio' => open_closed_ratio.to_f.round(2),
23
+ 'Open time in days' => open_time,
24
+ 'Min open time in days' => min_open_time,
25
+ 'Max open time in days' => max_open_time,
26
+ 'Average days request is opened' => average_open_time,
27
+ 'Health' => health
28
28
  }
29
29
  }.delete_if{|k,v| v.kind_of?(Float) && v.nan?}
30
30
  end
31
31
 
32
- def pulls_open_percent
33
- pulls_open.percent_of(pulls_all)
32
+ def open_percent
33
+ open.percent_of all
34
34
  end
35
35
 
36
- def pulls_closed_percent
37
- pulls_closed.percent_of(pulls_all)
36
+ def closed_percent
37
+ closed.percent_of all
38
38
  end
39
39
 
40
- def open_closed_pull_ratio
41
- result = pulls_open_percent / pulls_closed_percent
40
+ def open_closed_ratio
41
+ result = open_percent / closed_percent
42
42
  end
43
43
 
44
- def pull_open_time
45
- @pull_open_time.inject(:+)
44
+ def open_time
45
+ @open_times.inject(:+) || 0
46
46
  end
47
47
 
48
- def pull_average_open_time
49
- pull_open_time / pulls_open
48
+ def average_open_time
49
+ open_time / open if open > 0
50
50
  end
51
51
 
52
- def pull_min_open_time
53
- @pull_open_time.min
52
+ def min_open_time
53
+ @open_times.min
54
54
  end
55
55
 
56
- def pull_max_open_time
57
- @pull_open_time.max
56
+ def max_open_time
57
+ @open_times.max
58
58
  end
59
59
 
60
- def pulls_health
61
- case open_closed_pull_ratio.to_f
60
+ def health
61
+ case open_closed_ratio.to_f
62
62
  when 0..0.1
63
63
  "Good"
64
64
  when 0.1..0.2
@@ -72,7 +72,7 @@ module ProjectHealth
72
72
 
73
73
  private
74
74
  def calc_open_pull_time(pull)
75
- @pull_open_time << (DateTime.now.to_i - pull.created_at.to_datetime.to_i)/60/60/24
75
+ @open_times << (DateTime.now.to_i - pull.created_at.to_datetime.to_i)/60/60/24
76
76
  end
77
77
  end
78
78
  end
@@ -1,2 +1,3 @@
1
1
  require 'project-health/report/basic'
2
2
  require 'project-health/report/pull_requests'
3
+ require 'project-health/report/issues'
@@ -1,3 +1,3 @@
1
1
  module ProjectHealth
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: project-health
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-11 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: octokit
@@ -79,6 +79,7 @@ files:
79
79
  - lib/project-health/config.rb
80
80
  - lib/project-health/project.rb
81
81
  - lib/project-health/report/basic.rb
82
+ - lib/project-health/report/issues.rb
82
83
  - lib/project-health/report/pull_requests.rb
83
84
  - lib/project-health/reports.rb
84
85
  - lib/project-health/version.rb
@@ -109,3 +110,4 @@ specification_version: 3
109
110
  summary: Library for calculating project health report and analysis based on GitHub
110
111
  Activity data
111
112
  test_files: []
113
+ has_rdoc: