Class: Hubstats::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/hubstats/user.rb

Class Method Summary collapse

Instance Method Summary collapse

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



274
275
276
# File 'app/models/hubstats/user.rb', line 274

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



285
286
287
# File 'app/models/hubstats/user.rb', line 285

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



209
210
211
212
213
214
215
216
217
218
# File 'app/models/hubstats/user.rb', line 209

def self.create_or_update(github_user)
  github_user[:role] = github_user.delete :type  ##changing :type into :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



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'app/models/hubstats/user.rb', line 243

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 'signoffs'
      order("qa_signoff_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



229
230
231
232
233
234
235
# File 'app/models/hubstats/user.rb', line 229

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

#teamObject

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



293
294
295
# File 'app/models/hubstats/user.rb', line 293

def team
  teams.where(hubstats: true).first
end

#to_paramObject

Public - Designed to make a path for the show page when a repository is selected.

Returns - the show page of self.name



300
301
302
# File 'app/models/hubstats/user.rb', line 300

def to_param
  self.
end