Class: Hubstats::Deploy

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.group_by(group) ⇒ Object

Public - Groups the deploys based on the string passed in: ‘user’ or ‘repo’.

group - string that is the designated grouping

Returns - the data grouped



53
54
55
56
57
58
59
60
61
# File 'app/models/hubstats/deploy.rb', line 53

def self.group_by(group)
   if group == "user"
     with_user_name.order("user_name ASC")
   elsif group == "repo"
     with_repo_name.order("repo_name ASC")
   else
     all
   end
end

.order_with_date_range(start_date, end_date, order) ⇒ Object

Public - Orders the deploys within the start_date and end_date with by a given order.

start_date - the start of the date range end_date - the end of the data range order - the designated order to sort the data

Returns - the deploy data ordered



43
44
45
46
# File 'app/models/hubstats/deploy.rb', line 43

def self.order_with_date_range(start_date, end_date, order)
  order = ["ASC", "DESC"].detect{|order_type| order_type.to_s == order.to_s.upcase } || "DESC"
  deployed_in_date_range(start_date, end_date).order("hubstats_deploys.deployed_at #{order}")
end

Instance Method Details

#check_timeObject

Public - Checks if there is a deployed_at for a new deploy; if there isn’t, then assign it the current time.

Returns - the current time or the actual deployed_at time



10
11
12
# File 'app/models/hubstats/deploy.rb', line 10

def check_time
    self.deployed_at = Time.now.getutc if deployed_at.nil?
end

#find_comment_countObject

Public - Gathers all of the PRs and then counts all of the comments that are assigned to each PR.

Returns - the total amount of comments that all PRs to a deploy has



100
101
102
103
104
105
106
107
# File 'app/models/hubstats/deploy.rb', line 100

def find_comment_count
  pull_requests = self.pull_requests
  total_comments = 0
  pull_requests.each do |pull|
    total_comments += Hubstats::Comment.belonging_to_pull_request(pull.id).count(:all)
  end
  return total_comments
end

#find_net_additionsObject

Public - Gathers all PRs for a deploy, and then finds all of the additions and all of the deletions, then subtracts them to find the number of net additions.

Returns - the total number of deletions subtracted from the total number of additions



86
87
88
89
90
91
92
93
94
95
# File 'app/models/hubstats/deploy.rb', line 86

def find_net_additions
  pull_requests = self.pull_requests
  total_additions = 0
  total_deletions = 0
  pull_requests.each do |pull|
    total_additions += pull.additions.to_i
    total_deletions += pull.deletions.to_i
  end
  return total_additions - total_deletions
end

#total_changes(add) ⇒ Object

Public - Gathers all PRs for a deploy, and then either finds all of the additions or all of the deletions, depending on the symbol passed in.

add - symbol that reflects the type of data we want to add up

Returns - the total amount that has been added; either deletions or additions



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/hubstats/deploy.rb', line 69

def total_changes(add)
  pull_requests = self.pull_requests
  total = 0
  pull_requests.each do |pull|
    if add == :additions
      total += pull.additions.to_i
    elsif add == :deletions
      total += pull.deletions.to_i
    end
  end
  return total
end