hubstats 0.3.8 → 0.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.markdown +9 -0
  3. data/app/assets/javascripts/hubstats/bootstrap.js +38 -38
  4. data/app/assets/javascripts/hubstats/users.js +10 -5
  5. data/app/controllers/hubstats/application_controller.rb +0 -1
  6. data/app/controllers/hubstats/base_controller.rb +13 -0
  7. data/app/controllers/hubstats/deploys_controller.rb +26 -49
  8. data/app/controllers/hubstats/pull_requests_controller.rb +10 -14
  9. data/app/controllers/hubstats/repos_controller.rb +46 -24
  10. data/app/controllers/hubstats/users_controller.rb +24 -12
  11. data/app/models/hubstats/deploy.rb +36 -0
  12. data/app/models/hubstats/pull_request.rb +2 -2
  13. data/app/models/hubstats/repo.rb +63 -1
  14. data/app/models/hubstats/user.rb +29 -26
  15. data/app/views/hubstats/partials/_deploy-condensed.html.erb +1 -0
  16. data/app/views/hubstats/partials/_deploy.html.erb +1 -1
  17. data/app/views/hubstats/partials/_pull-condensed.html.erb +2 -1
  18. data/app/views/hubstats/partials/_pull.html.erb +1 -1
  19. data/app/views/hubstats/partials/_quick_addition_stats.html.erb +14 -2
  20. data/app/views/hubstats/partials/_quick_stats.html.erb +24 -12
  21. data/app/views/hubstats/partials/_repo.html.erb +37 -8
  22. data/app/views/hubstats/partials/_user.html.erb +1 -14
  23. data/app/views/hubstats/repos/dashboard.html.erb +1 -1
  24. data/app/views/hubstats/repos/show.html.erb +2 -9
  25. data/app/views/hubstats/tables/_repos.html.erb +19 -0
  26. data/app/views/hubstats/tables/_users.html.erb +1 -7
  27. data/app/views/hubstats/users/show.html.erb +3 -5
  28. data/config/routes.rb +8 -8
  29. data/lib/hubstats/github_api.rb +8 -6
  30. data/lib/hubstats/version.rb +1 -1
  31. data/spec/controllers/hubstats/deploys_controller_spec.rb +43 -47
  32. data/spec/controllers/hubstats/pull_requests_controller_spec.rb +41 -2
  33. data/spec/controllers/hubstats/repos_controller_spec.rb +62 -2
  34. data/spec/controllers/hubstats/users_controller_spec.rb +30 -2
  35. metadata +3 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGQ2OWYyM2Q1ZjVkOTJlOTdkMDAwNGRmZDY2OWIwZWZmMWM2MGYxNw==
4
+ ZDllYTczYjQ4OTgxNTcxNTIxNjBhMWM2MTRiYWNlNDlmMDBmOGQ3OA==
5
5
  data.tar.gz: !binary |-
6
- Y2QxN2YxY2U5YmEyMmU4ZDRmMGY5NmU5ZTFhNzVjMDE5MDI5YzBjMg==
6
+ NmRmMTc1NDQ3YWNlODkzYjY0MWVmMGI3YjgyNTVjODg1OTc5NmZlZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODRlNjczNzJmZDM1YWU0MzEwOWI3Yzg0ZTVjZTYwMTJmMjY4NjdiMjBhOTc5
10
- OGMxZjcwZjgxOTg1NWE4YTZiOGFkYTA0MjRhZGYxZDhjZTc4OTM0YjAxNDM0
11
- ZmUzYzUzOTc3MWQ4ZTIxN2QyNDExOThiMjE0OWFlMDI2YzE5NDI=
9
+ Y2UzZWIxMGI0NGMzYWI4ODFiOWM3YTg5M2MwM2YxMDhhZTg5NDRiY2E5NDJm
10
+ ZDYyMTI1MDk5NTljMzAzZDVjYzIxYWZhYWM5MTQ2OGQzNDQ5MDgxOWM4MzJk
11
+ N2I4OTEyMmY0N2IzN2M1OWFiYzM1ZDI4ZjE5M2MyODc0ZGM2NGM=
12
12
  data.tar.gz: !binary |-
13
- MDRlZGJmM2RkOGM0NTA3YjZmMzE5MzI0M2Q5NjYyZjU3OTVhNjYyNzM3OTlk
14
- OWFjYTIzOTVhODk3NTIwZGJjMWIxMjk2ZGM4MDI4NGM3YWE2N2MyZGNjYjJh
15
- Y2MwMDM2NDVjMTk2ZDMxMmJmZTFiMWY3OTZiMmJmZWQ3NDVhNGE=
13
+ YTFmZmI2ZjQ5NjU5MjA3ZjE5M2Q5NWVjYzlkMjY2N2JiOTk4YTIxMTQ0NjEw
14
+ Njc5YjI2ZTM0NGI4ZjI2NmE3NGU5Mzg3OTA4NjU0YjU5Mzg4NmM3MzYyNTc5
15
+ MzY3OGUwYTc2YmRlYzcyNjM5ZmExNmViZTVjZWM2MmM3MzFjODI=
@@ -1,3 +1,12 @@
1
+ #### v0.3.9
2
+ * Refactored Main Parts of Code
3
+
4
+ > Emma Sax: Brian Bergstrom: https://github.com/sportngin/hubstats/pull/57
5
+
6
+ * Changed Metrics Page, Wrote New Tests, Fixed Little Bugs
7
+
8
+ > Emma Sax: Brian Bergstrom: https://github.com/sportngin/hubstats/pull/56
9
+
1
10
  #### v0.3.8
2
11
  #### v0.3.7
3
12
  #### v0.3.6
@@ -4,7 +4,7 @@
4
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
5
5
  */
6
6
 
7
- if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript requires jQuery') }
7
+ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript requires jQuery') };
8
8
 
9
9
  /* ========================================================================
10
10
  * Bootstrap: transition.js v3.1.1
@@ -22,32 +22,32 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
22
22
  // ============================================================
23
23
 
24
24
  function transitionEnd() {
25
- var el = document.createElement('bootstrap')
25
+ var el = document.createElement('bootstrap');
26
26
 
27
27
  var transEndEventNames = {
28
28
  'WebkitTransition' : 'webkitTransitionEnd',
29
29
  'MozTransition' : 'transitionend',
30
30
  'OTransition' : 'oTransitionEnd otransitionend',
31
31
  'transition' : 'transitionend'
32
- }
32
+ };
33
33
 
34
34
  for (var name in transEndEventNames) {
35
35
  if (el.style[name] !== undefined) {
36
- return { end: transEndEventNames[name] }
36
+ return { end: transEndEventNames[name] };
37
37
  }
38
38
  }
39
39
 
40
- return false // explicit for ie8 ( ._.)
40
+ return false; // explicit for ie8 ( ._.)
41
41
  }
42
42
 
43
43
  // http://blog.alexmaccaw.com/css-transitions
44
44
  $.fn.emulateTransitionEnd = function (duration) {
45
- var called = false, $el = this
45
+ var called = false, $el = this;
46
46
  $(this).one($.support.transition.end, function () { called = true })
47
- var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
48
- setTimeout(callback, duration)
49
- return this
50
- }
47
+ var callback = function () { if (!called) {$($el).trigger($.support.transition.end)} };
48
+ setTimeout(callback, duration);
49
+ return this;
50
+ };
51
51
 
52
52
  $(function () {
53
53
  $.support.transition = transitionEnd()
@@ -70,71 +70,71 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
70
70
  // ALERT CLASS DEFINITION
71
71
  // ======================
72
72
 
73
- var dismiss = '[data-dismiss="alert"]'
73
+ var dismiss = '[data-dismiss="alert"]';
74
74
  var Alert = function (el) {
75
- $(el).on('click', dismiss, this.close)
76
- }
75
+ $(el).on('click', dismiss, this.close);
76
+ };
77
77
 
78
78
  Alert.prototype.close = function (e) {
79
- var $this = $(this)
80
- var selector = $this.attr('data-target')
79
+ var $this = $(this);
80
+ var selector = $this.attr('data-target');
81
81
 
82
82
  if (!selector) {
83
- selector = $this.attr('href')
84
- selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
85
- }
83
+ selector = $this.attr('href');
84
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, ''); // strip for ie7
85
+ };
86
86
 
87
- var $parent = $(selector)
87
+ var $parent = $(selector);
88
88
 
89
- if (e) e.preventDefault()
89
+ if (e) {e.preventDefault()};
90
90
 
91
91
  if (!$parent.length) {
92
- $parent = $this.hasClass('alert') ? $this : $this.parent()
93
- }
92
+ $parent = $this.hasClass('alert') ? $this : $this.parent();
93
+ };
94
94
 
95
- $parent.trigger(e = $.Event('close.bs.alert'))
95
+ $parent.trigger(e = $.Event('close.bs.alert'));
96
96
 
97
97
  if (e.isDefaultPrevented()) return
98
98
 
99
99
  $parent.removeClass('in')
100
100
 
101
101
  function removeElement() {
102
- $parent.trigger('closed.bs.alert').remove()
103
- }
102
+ $parent.trigger('closed.bs.alert').remove();
103
+ };
104
104
 
105
105
  $.support.transition && $parent.hasClass('fade') ?
106
106
  $parent
107
107
  .one($.support.transition.end, removeElement)
108
108
  .emulateTransitionEnd(150) :
109
- removeElement()
110
- }
109
+ removeElement();
110
+ };
111
111
 
112
112
 
113
113
  // ALERT PLUGIN DEFINITION
114
114
  // =======================
115
115
 
116
- var old = $.fn.alert
116
+ var old = $.fn.alert;
117
117
 
118
118
  $.fn.alert = function (option) {
119
119
  return this.each(function () {
120
- var $this = $(this)
121
- var data = $this.data('bs.alert')
120
+ var $this = $(this);
121
+ var data = $this.data('bs.alert');
122
122
 
123
- if (!data) $this.data('bs.alert', (data = new Alert(this)))
124
- if (typeof option == 'string') data[option].call($this)
125
- })
126
- }
123
+ if (!data) $this.data('bs.alert', (data = new Alert(this)));
124
+ if (typeof option === 'string') {data[option].call($this)};
125
+ });
126
+ };
127
127
 
128
- $.fn.alert.Constructor = Alert
128
+ $.fn.alert.Constructor = Alert;
129
129
 
130
130
 
131
131
  // ALERT NO CONFLICT
132
132
  // =================
133
133
 
134
134
  $.fn.alert.noConflict = function () {
135
- $.fn.alert = old
136
- return this
137
- }
135
+ $.fn.alert = old;
136
+ return this;
137
+ };
138
138
 
139
139
 
140
140
  // ALERT DATA-API
@@ -17,6 +17,11 @@ $(document).ready(function() {
17
17
  toggleOrder(queryParameters,$(this).attr('id'));
18
18
  });
19
19
 
20
+ // No longer using additions and deletions, but instead using net additions
21
+ $("#netadditions").on("click", function(){
22
+ toggleOrder(queryParameters,$(this).attr('id'));
23
+ });
24
+
20
25
  $("#additions").on("click", function(){
21
26
  toggleOrder(queryParameters,$(this).attr('id'));
22
27
  });
@@ -27,14 +32,14 @@ $(document).ready(function() {
27
32
  });
28
33
 
29
34
  function toggleOrder(queryParams, sort_by) {
30
- if (queryParameters["order"] !== undefined) {
31
- if (queryParameters["order"] === sort_by+"-desc" ) {
32
- updateQueryStringParameter(queryParameters,"order",sort_by+"-asc");
35
+ if (queryParams["order"] !== undefined) {
36
+ if (queryParams["order"] === sort_by+"-desc" ) {
37
+ updateQueryStringParameter(queryParams,"order",sort_by+"-asc");
33
38
  } else {
34
- updateQueryStringParameter(queryParameters,"order",sort_by+"-desc");
39
+ updateQueryStringParameter(queryParams,"order",sort_by+"-desc");
35
40
  }
36
41
  } else {
37
- updateQueryStringParameter(queryParameters,"order",sort_by+"-asc");
42
+ updateQueryStringParameter(queryParams,"order",sort_by+"-asc");
38
43
  }
39
44
  }
40
45
 
@@ -8,6 +8,5 @@ module Hubstats
8
8
  cookies[:hubstats_index] ||= 2
9
9
  @timespan = TIMESPAN_ARRAY[cookies[:hubstats_index].to_i][:date].ago.to_date
10
10
  end
11
-
12
11
  end
13
12
  end
@@ -0,0 +1,13 @@
1
+ require_dependency "hubstats/application_controller"
2
+
3
+ module Hubstats
4
+ class BaseController < Hubstats::ApplicationController
5
+ def grouping (group_request, group)
6
+ if group_request == "user"
7
+ @groups = group.to_a.group_by(&:user_name)
8
+ elsif group_request == "repo"
9
+ @groups = group.to_a.group_by(&:repo_name)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,7 @@
1
1
  require_dependency "hubstats/application_controller"
2
2
 
3
3
  module Hubstats
4
- class DeploysController < ApplicationController
4
+ class DeploysController < Hubstats::BaseController
5
5
 
6
6
  def index
7
7
  # sets to include user and repo, and sorts data
@@ -11,55 +11,24 @@ module Hubstats
11
11
  .order_with_timespan(@timespan, params[:order])
12
12
  .paginate(:page => params[:page], :per_page => 15)
13
13
 
14
- # enables grouping by user or repo
15
- if params[:group] == "user"
16
- @groups = @deploys.to_a.group_by(&:user_name)
17
- elsif params[:group] == "repo"
18
- @groups = @deploys.to_a.group_by(&:repo_name)
19
- end
14
+ grouping(params[:group], @deploys)
20
15
  end
21
16
 
22
17
  # show basic stats and pull requests from a single deploy
23
18
  def show
24
- @deploy = Hubstats::Deploy.includes(:repo).includes(:pull_requests).find(params[:id])
19
+ @deploy = Hubstats::Deploy.includes(:repo, :pull_requests).find(params[:id])
25
20
  repo = @deploy.repo
26
21
  @pull_requests = @deploy.pull_requests
27
22
  pull_request_count = @pull_requests.length
28
- net_additions = find_net_additions(@deploy.id)
29
- comment_count = find_comment_count(@deploy.id)
30
23
  @stats_basics = {
31
24
  pull_count: pull_request_count,
32
- net_additions: net_additions,
33
- comment_count: comment_count
25
+ net_additions: @deploy.find_net_additions,
26
+ comment_count: @deploy.find_comment_count,
27
+ additions: @deploy.total_changes(:additions),
28
+ deletions: @deploy.total_changes(:deletions)
34
29
  }
35
30
  end
36
31
 
37
- # finds all of the additions and deletions in all pull requests and then makes the net additions
38
- def find_net_additions(deploy_id)
39
- deploy = Hubstats::Deploy.find(deploy_id)
40
- pull_requests = deploy.pull_requests
41
- total_additions = 0
42
- total_deletions = 0
43
- pull_requests.each do |pull|
44
- total_additions += pull.additions.to_i
45
- total_deletions += pull.deletions.to_i
46
- end
47
- return total_additions - total_deletions
48
- end
49
-
50
- # returns the total amount of comments from all pull requests in a deploy
51
- def find_comment_count(deploy_id)
52
- deploy = Hubstats::Deploy.find(deploy_id)
53
- pull_requests = deploy.pull_requests
54
- total_comments = 0
55
- pull_requests.each do |pull|
56
- if pull.comments
57
- total_comments += Hubstats::Comment.belonging_to_pull_request(pull.id).includes(:user).created_since(@timespan).count(:all)
58
- end
59
- end
60
- return total_comments
61
- end
62
-
63
32
  # make a new deploy with all of the correct attributes
64
33
  def create
65
34
  if params[:git_revision].nil? || params[:repo_name].nil? || params[:pull_request_ids].nil?
@@ -69,29 +38,22 @@ module Hubstats
69
38
  @deploy.deployed_at = params[:deployed_at]
70
39
  @deploy.git_revision = params[:git_revision]
71
40
  @repo = Hubstats::Repo.where(full_name: params[:repo_name])
72
-
73
- # Check before assigning the repository
74
- if @repo.empty?
41
+
42
+ if !valid_repo(@repo)
75
43
  render text: "Repository name is invalid.", :status => 400 and return
76
44
  else
77
45
  @deploy.repo_id = @repo.first.id.to_i
78
46
  end
79
47
 
80
- # Check before assigning the pull requests
81
48
  @pull_request_id_array = params[:pull_request_ids].split(",").map {|i| i.strip.to_i}
82
- if @pull_request_id_array.empty? || @pull_request_id_array == [0]
49
+ if !valid_pr_ids
83
50
  render text: "No pull request ids given.", :status => 400 and return
84
51
  else
85
52
  @deploy.pull_requests = Hubstats::PullRequest.where(repo_id: @deploy.repo_id).where(number: @pull_request_id_array)
86
53
  end
87
54
 
88
- # Check before assigning the user_id
89
- if @deploy.pull_requests.first.nil?
55
+ if !valid_pulls
90
56
  render text: "Pull requests not valid", :status => 400 and return
91
- else
92
- if @deploy.pull_requests.first.merged_by
93
- @deploy.user_id = @deploy.pull_requests.first.merged_by
94
- end
95
57
  end
96
58
 
97
59
  if @deploy.save
@@ -101,5 +63,20 @@ module Hubstats
101
63
  end
102
64
  end
103
65
  end
66
+
67
+ def valid_repo(repo)
68
+ return !repo.empty?
69
+ end
70
+
71
+ def valid_pr_ids
72
+ return !@pull_request_id_array.empty? && @pull_request_id_array != [0]
73
+ end
74
+
75
+ def valid_pulls
76
+ pull = @deploy.pull_requests.first
77
+ return false if pull.nil? || pull.merged_by.nil?
78
+ @deploy.user_id = pull.merged_by
79
+ return true
80
+ end
104
81
  end
105
82
  end
@@ -1,7 +1,7 @@
1
1
  require_dependency "hubstats/application_controller"
2
2
 
3
3
  module Hubstats
4
- class PullRequestsController < ApplicationController
4
+ class PullRequestsController < Hubstats::BaseController
5
5
 
6
6
  def index
7
7
  URI.decode(params[:label]) if params[:label]
@@ -9,34 +9,30 @@ module Hubstats
9
9
  pull_ids = Hubstats::PullRequest
10
10
  .belonging_to_users(params[:users])
11
11
  .belonging_to_repos(params[:repos])
12
- .state_based_order(@timespan,params[:state],"ASC")
13
12
  .map(&:id)
14
13
 
15
14
  @labels = Hubstats::Label.with_a_pull_request(pull_ids).order("pull_request_count DESC")
16
15
 
17
- @pull_requests = Hubstats::PullRequest.includes(:user).includes(:repo)
16
+ @pull_requests = Hubstats::PullRequest.includes(:user, :repo)
18
17
  .belonging_to_users(params[:users]).belonging_to_repos(params[:repos])
19
18
  .group_by(params[:group]).with_label(params[:label])
20
19
  .state_based_order(@timespan,params[:state],params[:order])
21
20
  .paginate(:page => params[:page], :per_page => 15)
22
21
 
23
- if params[:group] == 'user'
24
- @groups = @pull_requests.to_a.group_by(&:user_name)
25
- elsif params[:group] == 'repo'
26
- @groups = @pull_requests.to_a.group_by(&:repo_name)
27
- end
28
-
22
+ grouping(params[:group], @pull_requests)
29
23
  end
30
24
 
31
25
  def show
32
26
  @repo = Hubstats::Repo.where(name: params[:repo]).first
33
27
  @pull_request = Hubstats::PullRequest.belonging_to_repo(@repo.id).where(id: params[:id]).first
34
- @comments = Hubstats::Comment.belonging_to_pull_request(params[:id]).includes(:user).created_since(@timespan).limit(20)
35
- @comment_count = Hubstats::Comment.belonging_to_pull_request(params[:id]).includes(:user).created_since(@timespan).count(:all)
36
- @deploys = Hubstats::Deploy.where(id: @pull_request.deploy_id)
28
+ @comments = Hubstats::Comment.belonging_to_pull_request(params[:id]).created_since(@timespan).limit(20)
29
+ comment_count = Hubstats::Comment.belonging_to_pull_request(params[:id]).created_since(@timespan).count(:all)
30
+ @deploys = Hubstats::Deploy.where(id: @pull_request.deploy_id).order("deployed_at DESC")
37
31
  @stats_basics = {
38
- comment_count: @comment_count,
39
- net_additions: @pull_request.additions.to_i - @pull_request.deletions.to_i
32
+ comment_count: comment_count,
33
+ net_additions: @pull_request.additions.to_i - @pull_request.deletions.to_i,
34
+ additions: @pull_request.additions.to_i,
35
+ deletions: @pull_request.deletions.to_i
40
36
  }
41
37
  end
42
38
 
@@ -19,40 +19,62 @@ module Hubstats
19
19
 
20
20
  def show
21
21
  @repo = Hubstats::Repo.where(name: params[:repo]).first
22
- @pull_requests = Hubstats::PullRequest.belonging_to_repo(@repo.id).updated_since(@timespan).order("updated_at DESC").limit(20)
23
- @users = Hubstats::User.with_pulls_or_comments(@timespan,@repo.id).only_active.limit(20)
24
- @deploys = Hubstats::Deploy.belonging_to_repo(@repo.id).deployed_since(@timespan).limit(20)
25
- @pull_count = Hubstats::PullRequest.belonging_to_repo(@repo.id).updated_since(@timespan).count(:all)
22
+ @pull_requests = Hubstats::PullRequest.belonging_to_repo(@repo.id).merged_since(@timespan).order("updated_at DESC").limit(20)
23
+ @pull_count = Hubstats::PullRequest.belonging_to_repo(@repo.id).merged_since(@timespan).count(:all)
24
+ @deploys = Hubstats::Deploy.belonging_to_repo(@repo.id).deployed_since(@timespan).order("deployed_at DESC").limit(20)
26
25
  @deploy_count = Hubstats::Deploy.belonging_to_repo(@repo.id).deployed_since(@timespan).count(:all)
26
+ @comment_count = Hubstats::Comment.belonging_to_repo(@repo.id).created_since(@timespan).count(:all)
27
27
  @user_count = Hubstats::User.with_pulls_or_comments(@timespan,@repo.id).only_active.length
28
- @stats_basics = {
29
- user_count: @user_count,
30
- deploy_count: @deploy_count,
31
- pull_count: @pull_count,
32
- comment_count: Hubstats::Comment.belonging_to_repo(@repo.id).created_since(@timespan).count(:all)
33
- }
34
- @stats_additions = {
35
- avg_additions: Hubstats::PullRequest.merged_since(@timespan).belonging_to_repo(@repo.id).average(:additions).to_i,
36
- avg_deletions: Hubstats::PullRequest.merged_since(@timespan).belonging_to_repo(@repo.id).average(:deletions).to_i,
37
- net_additions: Hubstats::PullRequest.merged_since(@timespan).belonging_to_repo(@repo.id).sum(:additions).to_i -
38
- Hubstats::PullRequest.merged_since(@timespan).belonging_to_repo(@repo.id).sum(:deletions).to_i
39
- }
28
+ @net_additions = Hubstats::PullRequest.belonging_to_repo(@repo.id).merged_since(@timespan).sum(:additions).to_i -
29
+ Hubstats::PullRequest.belonging_to_repo(@repo.id).merged_since(@timespan).sum(:deletions).to_i
30
+ @additions = Hubstats::PullRequest.belonging_to_repo(@repo.id).merged_since(@timespan).average(:additions)
31
+ @deletions = Hubstats::PullRequest.belonging_to_repo(@repo.id).merged_since(@timespan).average(:deletions)
32
+
33
+ stats
40
34
  end
41
35
 
42
36
  def dashboard
43
- @repos = Hubstats::Repo.with_recent_activity(@timespan)
37
+ if params[:query] ## For select 2.
38
+ @repos = Hubstats::Repo.where("name LIKE ?", "%#{params[:query]}%").order("name ASC")
39
+ elsif params[:id]
40
+ @repos = Hubstats::Repo.where(id: params[:id].split(",")).order("name ASC")
41
+ else
42
+ @repos = Hubstats::Repo.with_all_metrics(@timespan)
43
+ .with_id(params[:repos])
44
+ .custom_order(params[:order])
45
+ .paginate(:page => params[:page], :per_page => 15)
46
+ end
47
+
44
48
  @user_count = Hubstats::User.with_pulls_or_comments(@timespan).only_active.length
49
+ @deploy_count = Hubstats::Deploy.deployed_since(@timespan).count(:all)
50
+ @pull_count = Hubstats::PullRequest.merged_since(@timespan).count(:all)
51
+ @comment_count = Hubstats::Comment.created_since(@timespan).count(:all)
52
+ @net_additions = Hubstats::PullRequest.merged_since(@timespan).sum(:additions).to_i -
53
+ Hubstats::PullRequest.merged_since(@timespan).sum(:deletions).to_i
54
+ @additions = Hubstats::PullRequest.merged_since(@timespan).average(:additions)
55
+ @deletions = Hubstats::PullRequest.merged_since(@timespan).average(:deletions)
56
+
57
+ stats
58
+
59
+ respond_to do |format|
60
+ format.html
61
+ format.json { render :json => @repos}
62
+ end
63
+ end
64
+
65
+ def stats
66
+ @additions ||= 0
67
+ @deletions ||= 0
45
68
  @stats_basics = {
46
69
  user_count: @user_count,
47
- deploy_count: Hubstats::Deploy.count(:all),
48
- pull_count: Hubstats::PullRequest.merged_since(@timespan).count(:all),
49
- comment_count: Hubstats::Comment.created_since(@timespan).count(:all)
70
+ deploy_count: @deploy_count,
71
+ pull_count: @pull_count,
72
+ comment_count: @comment_count
50
73
  }
51
74
  @stats_additions = {
52
- avg_additions: Hubstats::PullRequest.merged_since(@timespan).average(:additions).to_i,
53
- avg_deletions: Hubstats::PullRequest.merged_since(@timespan).average(:deletions).to_i,
54
- net_additions: Hubstats::PullRequest.merged_since(@timespan).sum(:additions).to_i -
55
- Hubstats::PullRequest.merged_since(@timespan).sum(:deletions).to_i
75
+ avg_additions: @additions.round.to_i,
76
+ avg_deletions: @deletions.round.to_i,
77
+ net_additions: @net_additions
56
78
  }
57
79
  end
58
80
  end