hubstats 0.3.17 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +0 -1
  3. data/CHANGELOG.markdown +10 -0
  4. data/MIT-LICENSE +3 -1
  5. data/README.md +2 -2
  6. data/app/assets/javascripts/hubstats/application.js +80 -24
  7. data/app/assets/javascripts/hubstats/pull_requests.js +35 -3
  8. data/app/assets/javascripts/hubstats/select2.js +8 -1
  9. data/app/assets/javascripts/hubstats/users.js +17 -5
  10. data/app/assets/stylesheets/hubstats/application.css +39 -1
  11. data/app/assets/stylesheets/hubstats/bootstrap.css +0 -6
  12. data/app/assets/stylesheets/hubstats/deploys.css +2 -0
  13. data/app/assets/stylesheets/hubstats/label.css +2 -0
  14. data/app/assets/stylesheets/hubstats/octicons.css.erb +2 -0
  15. data/app/assets/stylesheets/hubstats/pull_requests.css +2 -0
  16. data/app/controllers/hubstats/application_controller.rb +12 -4
  17. data/app/controllers/hubstats/base_controller.rb +8 -0
  18. data/app/controllers/hubstats/deploys_controller.rb +31 -8
  19. data/app/controllers/hubstats/events_controller.rb +11 -0
  20. data/app/controllers/hubstats/pull_requests_controller.rb +9 -1
  21. data/app/controllers/hubstats/repos_controller.rb +17 -3
  22. data/app/controllers/hubstats/users_controller.rb +15 -0
  23. data/app/models/hubstats/comment.rb +13 -5
  24. data/app/models/hubstats/deploy.rb +29 -6
  25. data/app/models/hubstats/label.rb +16 -4
  26. data/app/models/hubstats/pull_request.rb +44 -2
  27. data/app/models/hubstats/repo.rb +48 -4
  28. data/app/models/hubstats/user.rb +130 -32
  29. data/app/views/hubstats/deploys/index.html.erb +1 -3
  30. data/app/views/hubstats/deploys/show.html.erb +7 -2
  31. data/app/views/hubstats/partials/_comment-condensed.html.erb +3 -0
  32. data/app/views/hubstats/partials/_comment.html.erb +3 -0
  33. data/app/views/hubstats/partials/_deploy-condensed.html.erb +2 -2
  34. data/app/views/hubstats/partials/_deploy.html.erb +1 -1
  35. data/app/views/hubstats/partials/_footer.html.erb +22 -0
  36. data/app/views/hubstats/partials/_header.html.erb +18 -10
  37. data/app/views/hubstats/partials/_pull-condensed.html.erb +2 -0
  38. data/app/views/hubstats/partials/_pull.html.erb +2 -0
  39. data/app/views/hubstats/partials/_quick_addition_stats.html.erb +2 -0
  40. data/app/views/hubstats/partials/_quick_stats.html.erb +1 -0
  41. data/app/views/hubstats/partials/_repo.html.erb +2 -3
  42. data/app/views/hubstats/partials/_user-condensed.html.erb +4 -0
  43. data/app/views/hubstats/partials/_user.html.erb +4 -2
  44. data/app/views/hubstats/pull_requests/index.html.erb +6 -1
  45. data/app/views/hubstats/pull_requests/show.html.erb +5 -0
  46. data/app/views/hubstats/repos/dashboard.html.erb +6 -4
  47. data/app/views/hubstats/repos/show.html.erb +6 -1
  48. data/app/views/hubstats/tables/_comments-condensed.html.erb +2 -1
  49. data/app/views/hubstats/tables/_comments.html.erb +2 -1
  50. data/app/views/hubstats/tables/_deploys-condensed.html.erb +1 -0
  51. data/app/views/hubstats/tables/_deploys.html.erb +1 -0
  52. data/app/views/hubstats/tables/_grouped_deploys.html.erb +1 -0
  53. data/app/views/hubstats/tables/_grouped_pulls.html.erb +1 -0
  54. data/app/views/hubstats/tables/_pulls-condensed.html.erb +1 -0
  55. data/app/views/hubstats/tables/_pulls.html.erb +1 -0
  56. data/app/views/hubstats/tables/_repos-condensed.html.erb +1 -0
  57. data/app/views/hubstats/tables/_repos.html.erb +1 -0
  58. data/app/views/hubstats/tables/_users-condensed.html.erb +1 -0
  59. data/app/views/hubstats/tables/_users.html.erb +1 -1
  60. data/app/views/hubstats/users/index.html.erb +3 -2
  61. data/app/views/hubstats/users/show.html.erb +7 -1
  62. data/app/views/layouts/hubstats/application.html.erb +4 -4
  63. data/config/routes.rb +2 -1
  64. data/db/seeds.rb +41 -0
  65. data/hubstats.gemspec +1 -0
  66. data/lib/generators/hubstats/install_generator.rb +2 -1
  67. data/lib/hub_helper.rb +18 -0
  68. data/lib/hubstats.rb +0 -30
  69. data/lib/hubstats/events_handler.rb +25 -7
  70. data/lib/hubstats/github_api.rb +43 -15
  71. data/lib/hubstats/version.rb +1 -1
  72. data/lib/tasks/hubstats_tasks.rake +1 -0
  73. data/lib/tasks/populate_task.rake +2 -1
  74. data/spec/controllers/hubstats/deploys_controller_spec.rb +0 -3
  75. data/spec/controllers/hubstats/pull_requests_controller_spec.rb +3 -4
  76. data/spec/controllers/hubstats/repos_controller_spec.rb +4 -5
  77. data/spec/factories/comment.rb +2 -1
  78. data/spec/factories/deploys.rb +1 -0
  79. data/spec/factories/pull_requests.rb +1 -0
  80. data/spec/factories/repo.rb +1 -0
  81. data/spec/factories/users.rb +2 -1
  82. data/spec/lib/hubstats/github_api_spec.rb +5 -5
  83. metadata +41 -26
  84. data/date_range +0 -0
@@ -1,3 +1,5 @@
1
+ /*For various label appearances throughout Hubstats*/
2
+
1
3
  .btn-label {
2
4
  font-weight: bold;
3
5
  color: #333333;
@@ -1,3 +1,5 @@
1
+ /*Octicons!*/
2
+
1
3
  @font-face {
2
4
  font-family: 'octicons';
3
5
  src: url('<%= asset_path("hubstats/octicons.eot") + "?#iefix" %>') format('embedded-opentype'),
@@ -2,6 +2,8 @@
2
2
  Place all the styles related to the matching controller here.
3
3
  They will automatically be included in application.css.
4
4
  */
5
+
6
+ /*For the filter boxes on the left side of the Pull Requests page*/
5
7
  .select2-container{
6
8
  width: 100%;
7
9
  }
@@ -1,13 +1,21 @@
1
1
  module Hubstats
2
2
  class ApplicationController < ApplicationController
3
-
4
3
  before_filter :set_time
5
4
 
5
+ # Private - Reads the cookie, and then either sets @start_date and @end_date to be the cookie's values
6
+ # or sets them to be today + 1 and two weeks ago.
7
+ #
8
+ # Returns - nothing
6
9
  private
7
10
  def set_time
8
- cookies[:hubstats_index] ||= 2
9
- @start_date = DATE_RANGE_ARRAY[cookies[:hubstats_index].to_i][:date].ago.to_date
10
- @end_date = Date.today + 1
11
+ cookie = cookies[:hubstats_dates]
12
+ if cookie == nil || cookie.include?("null")
13
+ @start_date = Date.today - 14
14
+ @end_date = Date.today + 1
15
+ else
16
+ @start_date = cookies[:hubstats_dates].split("~~").first.to_date
17
+ @end_date = cookies[:hubstats_dates].split("~~").last.to_date + 1
18
+ end
11
19
  end
12
20
  end
13
21
  end
@@ -2,6 +2,14 @@ require_dependency "hubstats/application_controller"
2
2
 
3
3
  module Hubstats
4
4
  class BaseController < Hubstats::ApplicationController
5
+
6
+ # Public - If the group is being asked to be grouped by user or repo, will make an array and group the data
7
+ # by either username or repo name.
8
+ #
9
+ # group_request - string of what the data should be grouped by
10
+ # group - the group of data to be grouped
11
+ #
12
+ # Returns - nothing
5
13
  def grouping (group_request, group)
6
14
  if group_request == "user"
7
15
  @groups = group.to_a.group_by(&:user_name)
@@ -3,8 +3,11 @@ require_dependency "hubstats/application_controller"
3
3
  module Hubstats
4
4
  class DeploysController < Hubstats::BaseController
5
5
 
6
+ # Public - Will list the deploys that correspond with selected repos, users, orders, and groupings. Only shows
7
+ # deploys within the @start_date and @end_date.
8
+ #
9
+ # Returns - the deploy data
6
10
  def index
7
- # sets to include user and repo, and sorts data
8
11
  @deploys = Hubstats::Deploy.includes(:repo, :pull_requests, :user)
9
12
  .belonging_to_users(params[:users]).belonging_to_repos(params[:repos])
10
13
  .group_by(params[:group])
@@ -14,7 +17,10 @@ module Hubstats
14
17
  grouping(params[:group], @deploys)
15
18
  end
16
19
 
17
- # show basic stats and pull requests from a single deploy
20
+ # Public - Shows the single deploy and all of the stats and pull requests about that deploy. Stats and PRs only
21
+ # include info that happened between @start_date and @end_date.
22
+ #
23
+ # Returns - the stats and data of the deploy
18
24
  def show
19
25
  @deploy = Hubstats::Deploy.includes(:repo, :pull_requests).find(params[:id])
20
26
  repo = @deploy.repo
@@ -29,7 +35,10 @@ module Hubstats
29
35
  }
30
36
  end
31
37
 
32
- # make a new deploy with all of the correct attributes
38
+ # Public - Creates a new deploy with the git_revision. Passed in the repo name and a string of PR ids
39
+ # that are then used to find the repo_id, PR id array. The user_id is found through one of the pull requests.
40
+ #
41
+ # Returns - nothing, but makes a new deploy
33
42
  def create
34
43
  if params[:git_revision].nil? || params[:repo_name].nil? || params[:pull_request_ids].nil?
35
44
  render text: "Missing a necessary parameter: git revision, pull request ids, or repository name.", :status => 400 and return
@@ -45,11 +54,11 @@ module Hubstats
45
54
  @deploy.repo_id = @repo.first.id.to_i
46
55
  end
47
56
 
48
- @pull_request_id_array = params[:pull_request_ids].split(",").map {|i| i.strip.to_i}
49
- if !valid_pr_ids
57
+ pull_request_id_array = params[:pull_request_ids].split(",").map {|i| i.strip.to_i}
58
+ if !valid_pr_ids(pull_request_id_array)
50
59
  render text: "No pull request ids given.", :status => 400 and return
51
60
  else
52
- @deploy.pull_requests = Hubstats::PullRequest.where(repo_id: @deploy.repo_id).where(number: @pull_request_id_array)
61
+ @deploy.pull_requests = Hubstats::PullRequest.where(repo_id: @deploy.repo_id).where(number: pull_request_id_array)
53
62
  end
54
63
 
55
64
  if !valid_pulls
@@ -64,14 +73,28 @@ module Hubstats
64
73
  end
65
74
  end
66
75
 
76
+ # Public - Checks if the repo that's passed in is empty.
77
+ #
78
+ # repo - the repository
79
+ #
80
+ # Returns - true if the repo is valid
67
81
  def valid_repo(repo)
68
82
  return !repo.empty?
69
83
  end
70
84
 
71
- def valid_pr_ids
72
- return !@pull_request_id_array.empty? && @pull_request_id_array != [0]
85
+ # Public - Checks if the array is empty or if the ids in the array are invalid.
86
+ #
87
+ # pull_id_array - the array of pull request ids
88
+ #
89
+ # Returns - returns true if the array neither is empty nor comes out to [0]
90
+ def valid_pr_ids(pull_id_array)
91
+ return !pull_id_array.empty? && pull_id_array != [0]
73
92
  end
74
93
 
94
+ # Public - Checks if the first pull assigned to the new deploy is nil, if the merged_by part is nil. If nothing is
95
+ # nil, it will set the user_id of the deploy to be the merged_by of the pull.
96
+ #
97
+ # Returns - true and changes the user_id of deploy, else returns false
75
98
  def valid_pulls
76
99
  pull = @deploy.pull_requests.first
77
100
  return false if pull.nil? || pull.merged_by.nil?
@@ -3,6 +3,12 @@ require_dependency "hubstats/application_controller"
3
3
  module Hubstats
4
4
  class EventsController < ApplicationController
5
5
 
6
+ # Public - Verifies that the request we're receiving is a new event, and then will handle it and route
7
+ # it to the correct place.
8
+ #
9
+ # request - the request of the new event
10
+ #
11
+ # Returns - nothing, but makes a new event
6
12
  def handler
7
13
  verify_signature(request)
8
14
 
@@ -14,6 +20,11 @@ module Hubstats
14
20
  render :nothing => true
15
21
  end
16
22
 
23
+ # Pulbic - Will check that the request passed is a valid signature.
24
+ #
25
+ # request - the signature to be checked
26
+ #
27
+ # Returns - an error if the signatures don't match
17
28
  private
18
29
  def verify_signature(request)
19
30
  request.body.rewind
@@ -3,6 +3,11 @@ require_dependency "hubstats/application_controller"
3
3
  module Hubstats
4
4
  class PullRequestsController < Hubstats::BaseController
5
5
 
6
+ # Public - Will correctly add the labels to the side of the page based on which PRs are showing, and will
7
+ # come up with the list of PRs to show, based on users, repos, grouping, labels, and order. Only shows
8
+ # PRs within @start_date and @end_date.
9
+ #
10
+ # Returns - the pull request data
6
11
  def index
7
12
  URI.decode(params[:label]) if params[:label]
8
13
 
@@ -18,13 +23,16 @@ module Hubstats
18
23
  grouping(params[:group], @pull_requests)
19
24
  end
20
25
 
26
+ # Public - Will show the particular pull request selected, including all of the basic stats, deploy (only if
27
+ # PR is closed), and comments associated with that PR within the @start_date and @end_date.
28
+ #
29
+ # Returns - the specific details of the pull request
21
30
  def show
22
31
  @repo = Hubstats::Repo.where(name: params[:repo]).first
23
32
  @pull_request = Hubstats::PullRequest.belonging_to_repo(@repo.id).where(id: params[:id]).first
24
33
  @comments = Hubstats::Comment.belonging_to_pull_request(params[:id]).created_in_date_range(@start_date, @end_date).limit(20)
25
34
  comment_count = Hubstats::Comment.belonging_to_pull_request(params[:id]).created_in_date_range(@start_date, @end_date).count(:all)
26
35
  @deploys = Hubstats::Deploy.where(id: @pull_request.deploy_id).order("deployed_at DESC")
27
-
28
36
  @stats_basics = {
29
37
  comment_count: comment_count,
30
38
  net_additions: @pull_request.additions.to_i - @pull_request.deletions.to_i,
@@ -1,8 +1,12 @@
1
1
  require_dependency "hubstats/application_controller"
2
2
 
3
3
  module Hubstats
4
- class ReposController < ApplicationController
4
+ class ReposController < Hubstats::BaseController
5
5
 
6
+ # Public - Lists all of the repos, either in alphabetical order, by query params, or with activity in between
7
+ # @start_date and @end_date.
8
+ #
9
+ # Returns - the repository data
6
10
  def index
7
11
  if params[:query] ## For select 2
8
12
  @repos = Hubstats::Repo.where("name LIKE ?", "%#{params[:query]}%").order("name ASC")
@@ -17,6 +21,10 @@ module Hubstats
17
21
  end
18
22
  end
19
23
 
24
+ # Public - Shows the selected repository and all of the basic stats associated with that repository, including
25
+ # all deploys and merged PRs in that repo within @start_date and @end_date.
26
+ #
27
+ # Returns - the specific repository data
20
28
  def show
21
29
  @repo = Hubstats::Repo.where(name: params[:repo]).first
22
30
  @pull_requests = Hubstats::PullRequest.belonging_to_repo(@repo.id).merged_in_date_range(@start_date, @end_date).order("updated_at DESC").limit(20)
@@ -24,7 +32,7 @@ module Hubstats
24
32
  @deploys = Hubstats::Deploy.belonging_to_repo(@repo.id).deployed_in_date_range(@start_date, @end_date).order("deployed_at DESC").limit(20)
25
33
  @deploy_count = Hubstats::Deploy.belonging_to_repo(@repo.id).deployed_in_date_range(@start_date, @end_date).count(:all)
26
34
  @comment_count = Hubstats::Comment.belonging_to_repo(@repo.id).created_in_date_range(@start_date, @end_date).count(:all)
27
- @user_count = Hubstats::User.with_pulls_or_comments(@start_date, @end_date, @repo.id).only_active.length
35
+ @user_count = Hubstats::User.with_pulls_or_comments_or_deploys(@start_date, @end_date, @repo.id).only_active.length
28
36
  @net_additions = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_repo(@repo.id).sum(:additions).to_i -
29
37
  Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_repo(@repo.id).sum(:deletions).to_i
30
38
  @additions = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).belonging_to_repo(@repo.id).average(:additions)
@@ -33,6 +41,10 @@ module Hubstats
33
41
  stats
34
42
  end
35
43
 
44
+ # Public - Shows all of the repositories with individual stats for each repo. Also shows the stats for all of
45
+ # the repositories within @start_date and @end_date.
46
+ #
47
+ # Returns - the stats for the entirety of Hubstats and all repos
36
48
  def dashboard
37
49
  if params[:query] ## For select 2
38
50
  @repos = Hubstats::Repo.where("name LIKE ?", "%#{params[:query]}%").order("name ASC")
@@ -45,7 +57,7 @@ module Hubstats
45
57
  .paginate(:page => params[:page], :per_page => 15)
46
58
  end
47
59
 
48
- @user_count = Hubstats::User.with_pulls_or_comments(@start_date, @end_date).only_active.length
60
+ @user_count = Hubstats::User.with_pulls_or_comments_or_deploys(@start_date, @end_date).only_active.length
49
61
  @deploy_count = Hubstats::Deploy.deployed_in_date_range(@start_date, @end_date).count(:all)
50
62
  @pull_count = Hubstats::PullRequest.merged_in_date_range(@start_date, @end_date).count(:all)
51
63
  @comment_count = Hubstats::Comment.created_in_date_range(@start_date, @end_date).count(:all)
@@ -62,6 +74,8 @@ module Hubstats
62
74
  end
63
75
  end
64
76
 
77
+ # stats
78
+ # Will assign all of the stats for both the show page and the dashboard page.
65
79
  def stats
66
80
  @additions ||= 0
67
81
  @deletions ||= 0
@@ -3,11 +3,20 @@ require_dependency "hubstats/application_controller"
3
3
  module Hubstats
4
4
  class UsersController < ApplicationController
5
5
 
6
+ # Public - Shows all of the users in either alphabetical order, by filter params, or that have done things in
7
+ # github between the selected @start_date and @end_date.
8
+ #
9
+ # Returns - the user data
6
10
  def index
7
11
  if params[:query] ## For select 2
8
12
  @users = Hubstats::User.where("login LIKE ?", "%#{params[:query]}%").order("login ASC")
9
13
  elsif params[:id]
10
14
  @users = Hubstats::User.where(id: params[:id].split(",")).order("login ASC")
15
+ elsif params[:repos]
16
+ @users = Hubstats::User.only_active.with_contributions(@start_date, @end_date, params[:repos])
17
+ .with_id(params[:users])
18
+ .custom_order(params[:order])
19
+ .paginate(:page => params[:page], :per_page => 15)
11
20
  else
12
21
  @users = Hubstats::User.only_active.with_all_metrics(@start_date, @end_date)
13
22
  .with_id(params[:users])
@@ -21,6 +30,10 @@ module Hubstats
21
30
  end
22
31
  end
23
32
 
33
+ # Public - Will show the specific user along with the basic stats about that user, including all deploys
34
+ # and merged PRs they've done within the @start_date and @end_date.
35
+ #
36
+ # Returns - the data of the specific user
24
37
  def show
25
38
  @user = Hubstats::User.where(login: params[:id]).first
26
39
  @pull_requests = Hubstats::PullRequest.belonging_to_user(@user.id).merged_in_date_range(@start_date, @end_date).order("updated_at DESC").limit(20)
@@ -36,6 +49,8 @@ module Hubstats
36
49
  stats
37
50
  end
38
51
 
52
+ # stats
53
+ # Shows the basic stats for both the user show page.
39
54
  def stats
40
55
  @additions ||= 0
41
56
  @deletions ||= 0
@@ -1,5 +1,15 @@
1
1
  module Hubstats
2
2
  class Comment < ActiveRecord::Base
3
+
4
+ # Various checks that can be used to filter and find info about comments.
5
+ scope :created_in_date_range, lambda {|start_date, end_date| where("hubstats_comments.created_at BETWEEN ? AND ?", start_date, end_date)}
6
+ scope :belonging_to_pull_request, lambda {|pull_request_id| where(pull_request_id: pull_request_id)}
7
+ scope :belonging_to_user, lambda {|user_id| where(user_id: user_id)}
8
+ scope :belonging_to_repo, lambda {|repo_id| where(repo_id: repo_id)}
9
+
10
+ # Public - Gets the number of PRs that a user commented on that were not their own PR.
11
+ #
12
+ # Returns - the number of PRs that a specific user has reviewed
3
13
  scope :pull_reviews_count, lambda {
4
14
  select("hubstats_comments.user_id")
5
15
  .select("COUNT(DISTINCT hubstats_pull_requests.id) as total")
@@ -8,11 +18,6 @@ module Hubstats
8
18
  .group("hubstats_comments.user_id")
9
19
  }
10
20
 
11
- scope :created_in_date_range, lambda {|start_date, end_date| where("hubstats_comments.created_at BETWEEN ? AND ?", start_date, end_date)}
12
- scope :belonging_to_pull_request, lambda {|pull_request_id| where(pull_request_id: pull_request_id)}
13
- scope :belonging_to_user, lambda {|user_id| where(user_id: user_id)}
14
- scope :belonging_to_repo, lambda {|repo_id| where(repo_id: repo_id)}
15
-
16
21
  attr_accessible :id, :html_url, :url, :pull_request_url, :diff_hunk, :path,
17
22
  :position, :original_position, :line, :commit_id, :original_commit_id,
18
23
  :body, :created_at, :updated_at, :user_id, :pull_request_id, :repo_id,
@@ -22,6 +27,9 @@ module Hubstats
22
27
  belongs_to :pull_request
23
28
  belongs_to :repo
24
29
 
30
+ # Public - Makes a new comment based on a GitHub webhook occurrence. Assigns the user and the PR.
31
+ #
32
+ # github_comment - the information from Github about the comment
25
33
  def self.create_or_update(github_comment)
26
34
  github_comment = github_comment.to_h.with_indifferent_access if github_comment.respond_to? :to_h
27
35
 
@@ -4,10 +4,14 @@ module Hubstats
4
4
  before_validation :check_time, on: :create
5
5
  validates :git_revision, :deployed_at, :repo_id, presence: true
6
6
 
7
+ # Public - Checks if there is a deployed_at for a new deploy; if there isn't, then assign it the current time.
8
+ #
9
+ # Returns - the current time or the actual deployed_at time
7
10
  def check_time
8
11
  self.deployed_at = Time.now.getutc if deployed_at.nil?
9
12
  end
10
13
 
14
+ # Various checks that can be used to filter, sort, and find info about deploys.
11
15
  scope :deployed_in_date_range, lambda {|start_date, end_date| where("hubstats_deploys.deployed_at BETWEEN ? AND ?", start_date, end_date)}
12
16
  scope :group, lambda {|group| group_by(:repo_id) if group }
13
17
  scope :belonging_to_repo, lambda {|repo_id| where(repo_id: repo_id)}
@@ -23,13 +27,23 @@ module Hubstats
23
27
  belongs_to :repo
24
28
  has_many :pull_requests
25
29
 
26
- # Order the data in a given date range in a given order
30
+ # Public - Orders the deploys within the start_date and end_date with by a given order.
31
+ #
32
+ # start_date - the start of the date range
33
+ # end_date - the end of the data range
34
+ # order - the designated order to sort the data
35
+ #
36
+ # Returns - the deploy data ordered
27
37
  def self.order_with_date_range(start_date, end_date, order)
28
38
  order = ["ASC", "DESC"].detect{|order_type| order_type.to_s == order.to_s.upcase } || "DESC"
29
39
  deployed_in_date_range(start_date, end_date).order("hubstats_deploys.deployed_at #{order}")
30
40
  end
31
41
 
32
- # Sorts based on whether data is being grouped by user or repo
42
+ # Public - Groups the deploys based on the string passed in: 'user' or 'repo'.
43
+ #
44
+ # group - string that is the designated grouping
45
+ #
46
+ # Returns - the data grouped
33
47
  def self.group_by(group)
34
48
  if group == "user"
35
49
  with_user_name.order("user_name ASC")
@@ -40,7 +54,12 @@ module Hubstats
40
54
  end
41
55
  end
42
56
 
43
- # finds the total number of additions or deletions for all pull requests in this deploy
57
+ # Public - Gathers all PRs for a deploy, and then either finds all of the additions or all of the
58
+ # deletions, depending on the symbol passed in.
59
+ #
60
+ # add - symbol that reflects the type of data we want to add up
61
+ #
62
+ # Returns - the total amount that has been added; either deletions or additions
44
63
  def total_changes(add)
45
64
  pull_requests = self.pull_requests
46
65
  total = 0
@@ -54,7 +73,10 @@ module Hubstats
54
73
  return total
55
74
  end
56
75
 
57
- # finds all of the additions and deletions in all pull requests and then makes the net additions
76
+ # Public - Gathers all PRs for a deploy, and then finds all of the additions and all of the deletions,
77
+ # then subtracts them to find the number of net additions.
78
+ #
79
+ # Returns - the total number of deletions subtracted from the total number of additions
58
80
  def find_net_additions
59
81
  pull_requests = self.pull_requests
60
82
  total_additions = 0
@@ -66,7 +88,9 @@ module Hubstats
66
88
  return total_additions - total_deletions
67
89
  end
68
90
 
69
- # returns the total amount of comments from all pull requests in a deploy
91
+ # Public - Gathers all of the PRs and then counts all of the comments that are assigned to each PR.
92
+ #
93
+ # Returns - the total amount of comments that all PRs to a deploy has
70
94
  def find_comment_count
71
95
  pull_requests = self.pull_requests
72
96
  total_comments = 0
@@ -75,6 +99,5 @@ module Hubstats
75
99
  end
76
100
  return total_comments
77
101
  end
78
-
79
102
  end
80
103
  end
@@ -1,6 +1,16 @@
1
1
  module Hubstats
2
2
  class Label < ActiveRecord::Base
3
3
 
4
+ # Various checks that can be used to filter and find info about labels.
5
+ scope :with_ids, lambda {|pull_ids| (where("hubstats_labels_pull_requests.pull_request_id" => pull_ids))}
6
+ scope :with_state, lambda {|state| (where(state: state) unless state == 'all') if state}
7
+
8
+ # Public - Counts all of the labels that are assigned to one of the PRs that is passed in. This is then
9
+ # merged with the list of PRs. It also shows a count of the number of PRs with each specific label.
10
+ #
11
+ # pull_requests - the PRs that are shown on the given index page
12
+ #
13
+ # Returns - the labels data
4
14
  def self.count_by_pull_requests(pull_requests)
5
15
  select("hubstats_labels.*")
6
16
  .select("COUNT(hubstats_labels_pull_requests.pull_request_id) AS pull_request_count")
@@ -10,14 +20,16 @@ module Hubstats
10
20
  .order("pull_request_count DESC")
11
21
  end
12
22
 
13
- scope :with_ids, lambda {|pull_ids| (where("hubstats_labels_pull_requests.pull_request_id" => pull_ids))}
14
-
15
- scope :with_state, lambda {|state| (where(state: state) unless state == 'all') if state}
16
-
17
23
  attr_accessible :url, :name, :color
18
24
 
19
25
  has_and_belongs_to_many :pull_requests, :join_table => 'hubstats_labels_pull_requests'
20
26
 
27
+ # Public - Checks if the label is currently existing, and if it isn't, then makes a new label with
28
+ # the specifications that are passed in.
29
+ #
30
+ # label - the info that's passed in about the new label
31
+ #
32
+ # Returns - the label
21
33
  def self.first_or_create(label)
22
34
  if exists = Hubstats::Label.where(name: label[:name]).first
23
35
  return exists