Class: Hubstats::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Hubstats::User
- Defined in:
- app/models/hubstats/user.rb
Class Method Summary collapse
-
.count_active_developers(start_date, end_date) ⇒ Object
Public - Counts all of the pull requests for the users and sees if the count of PRs is greater than 0 (if they are a developer).
-
.count_active_reviewers(start_date, end_date) ⇒ Object
Public - Counts all of the comments for the users and sees if the count of comments is greater than 0 (if they are a reviewer).
-
.create_or_update(github_user) ⇒ Object
Public - Creates a new user form a GitHub webhook.
-
.custom_order(order_params) ⇒ Object
Public - Designed so that the list of users can be ordered based on deploys, pulls, comments, net additions, or name.
-
.with_pulls_or_comments_or_deploys(start_date, end_date, repo_id = nil) ⇒ Object
Public - If a repo_id is provided, will sort/filter the users based on the number of comments, deploys, and pull requests on that repo within the start_date and end_date.
Instance Method Summary collapse
-
#team ⇒ Object
Public - Gets the first team where the user is belongs to and where hubstats bool is true.
-
#to_param ⇒ Object
Public - Designed to make a path for the show page when a repository is selected.
Class Method Details
.count_active_developers(start_date, end_date) ⇒ Object
Public - Counts all of the pull requests for the users and sees if the count of PRs is greater than 0 (if they are a developer). Then counts all of the developers.
start_date - the starting date that we want to count the PRs from end_date - the ending date that we want to count the PRs from
Returns - the count of total users that have PRs > 0
244 245 246 |
# File 'app/models/hubstats/user.rb', line 244 def self.count_active_developers(start_date, end_date) self.pull_requests_count(start_date, end_date).is_developer.to_a.count end |
.count_active_reviewers(start_date, end_date) ⇒ Object
Public - Counts all of the comments for the users and sees if the count of comments is greater than 0 (if they are a reviewer). Then counts all of the reviewers.
start_date - the starting date that we want to count the comments from end_date - the ending date that we want to count the comments from
Returns - the count of total users that have comments > 0
255 256 257 |
# File 'app/models/hubstats/user.rb', line 255 def self.count_active_reviewers(start_date, end_date) self.comments_count(start_date, end_date).is_reviewer.to_a.count end |
.create_or_update(github_user) ⇒ Object
Public - Creates a new user form a GitHub webhook.
github_user - the info from Github about the new or updated user
Returns - the user
181 182 183 184 185 186 187 188 189 190 |
# File 'app/models/hubstats/user.rb', line 181 def self.create_or_update(github_user) github_user[:role] = github_user.delete :type ##changing :type in to :role github_user = github_user.to_h.with_indifferent_access unless github_user.is_a? Hash user_data = github_user.slice(*Hubstats::User.column_names.map(&:to_sym)) user = Hubstats::User.where(:id => user_data[:id]).first_or_create(user_data) return user if user.update_attributes(user_data) Rails.logger.warn user.errors.inspect end |
.custom_order(order_params) ⇒ Object
Public - Designed so that the list of users can be ordered based on deploys, pulls, comments, net additions, or name. If none of these are selected, then the default is to order by pull request count in descending order.
order_params - the param of what the users should be sorted by
Returns - the user data ordered
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'app/models/hubstats/user.rb', line 215 def self.custom_order(order_params) if order_params order = order_params.include?('asc') ? "ASC" : "DESC" case order_params.split('-').first when 'deploys' order("deploy_count #{order}") when 'pulls' order("pull_request_count #{order}") when 'comments' order("comment_count #{order}") when 'netadditions' order("additions - deletions #{order}") when 'name' order("login #{order}") else order("pull_request_count #{order}") end else order("pull_request_count DESC") end end |
.with_pulls_or_comments_or_deploys(start_date, end_date, repo_id = nil) ⇒ Object
Public - If a repo_id is provided, will sort/filter the users based on the number of comments, deploys, and pull requests on that repo within the start_date and end_date. If no repo_id is provided, will still sort, just considering all PRs and comments within the two dates.
start_date - the start of the date range end_date - the end of the data range repo_id - the id of the repository (optional)
Returns - the count of data that fulfills the sql queries
201 202 203 204 205 206 207 |
# File 'app/models/hubstats/user.rb', line 201 def self.with_pulls_or_comments_or_deploys(start_date, end_date, repo_id = nil) if repo_id pull_comment_deploy_count_by_repo(start_date, end_date, repo_id) else pull_comment_deploy_count(start_date, end_date) end end |
Instance Method Details
#team ⇒ Object
Public - Gets the first team where the user is belongs to and where hubstats bool is true.
Returns - the first team that the user belongs to where hubstats bool is true, if nothing meets these qualifications, nil is returned
263 264 265 |
# File 'app/models/hubstats/user.rb', line 263 def team teams.where(hubstats: true).first end |
#to_param ⇒ Object
Public - Designed to make a path for the show page when a repository is selected.
Returns - the show page of self.name
270 271 272 |
# File 'app/models/hubstats/user.rb', line 270 def to_param self.login end |