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

Sorts based on whether data is being grouped by user or repo



33
34
35
36
37
38
39
40
41
# File 'app/models/hubstats/deploy.rb', line 33

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
     scoped
   end
end

.order_with_date_range(start_date, end_date, order) ⇒ Object

Order the data in a given date range in a given order



27
28
29
30
# File 'app/models/hubstats/deploy.rb', line 27

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



7
8
9
# File 'app/models/hubstats/deploy.rb', line 7

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

#find_comment_countObject

returns the total amount of comments from all pull requests in a deploy



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

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

finds all of the additions and deletions in all pull requests and then makes the net additions



58
59
60
61
62
63
64
65
66
67
# File 'app/models/hubstats/deploy.rb', line 58

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

finds the total number of additions or deletions for all pull requests in this deploy



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/hubstats/deploy.rb', line 44

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