2015-11-13 18:20:48 +00:00
|
|
|
class GlobalMilestone
|
2015-10-14 10:33:39 +00:00
|
|
|
attr_accessor :title, :milestones
|
2015-10-09 04:24:55 +00:00
|
|
|
alias_attribute :name, :title
|
|
|
|
|
2015-11-13 18:20:48 +00:00
|
|
|
def self.build_collection(milestones)
|
|
|
|
milestones = milestones.group_by(&:title)
|
|
|
|
|
|
|
|
milestones.map do |title, milestones|
|
|
|
|
new(title, milestones)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 08:57:36 +00:00
|
|
|
def initialize(title, milestones)
|
|
|
|
@title = title
|
|
|
|
@milestones = milestones
|
|
|
|
end
|
|
|
|
|
2014-06-27 08:14:57 +00:00
|
|
|
def safe_title
|
2014-06-30 14:18:26 +00:00
|
|
|
@title.parameterize
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
2015-11-13 18:20:48 +00:00
|
|
|
|
2014-06-26 11:32:35 +00:00
|
|
|
def projects
|
2014-06-30 11:27:17 +00:00
|
|
|
milestones.map { |milestone| milestone.project }
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def issue_count
|
2014-06-30 11:27:17 +00:00
|
|
|
milestones.map { |milestone| milestone.issues.count }.sum
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_requests_count
|
2014-06-30 11:27:17 +00:00
|
|
|
milestones.map { |milestone| milestone.merge_requests.count }.sum
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|
|
|
|
|
2014-06-27 08:14:57 +00:00
|
|
|
def open_items_count
|
2014-06-30 11:27:17 +00:00
|
|
|
milestones.map { |milestone| milestone.open_items_count }.sum
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
|
|
|
|
2014-06-26 08:57:36 +00:00
|
|
|
def closed_items_count
|
2014-06-30 11:27:17 +00:00
|
|
|
milestones.map { |milestone| milestone.closed_items_count }.sum
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def total_items_count
|
2014-06-30 11:27:17 +00:00
|
|
|
milestones.map { |milestone| milestone.total_items_count }.sum
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def percent_complete
|
|
|
|
((closed_items_count * 100) / total_items_count).abs
|
|
|
|
rescue ZeroDivisionError
|
2015-05-26 18:44:04 +00:00
|
|
|
0
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|
2014-06-26 09:58:40 +00:00
|
|
|
|
|
|
|
def state
|
2014-06-30 11:27:17 +00:00
|
|
|
state = milestones.map { |milestone| milestone.state }
|
2014-06-26 11:32:35 +00:00
|
|
|
|
2014-07-14 13:25:09 +00:00
|
|
|
if state.count('closed') == state.size
|
2014-06-26 09:58:40 +00:00
|
|
|
'closed'
|
2014-07-14 13:25:09 +00:00
|
|
|
else
|
|
|
|
'active'
|
2014-06-26 09:58:40 +00:00
|
|
|
end
|
|
|
|
end
|
2014-06-27 08:14:57 +00:00
|
|
|
|
|
|
|
def active?
|
|
|
|
state == 'active'
|
|
|
|
end
|
|
|
|
|
|
|
|
def closed?
|
|
|
|
state == 'closed'
|
|
|
|
end
|
|
|
|
|
2014-06-30 08:54:57 +00:00
|
|
|
def issues
|
2015-11-13 18:20:48 +00:00
|
|
|
@issues ||= milestones.map(&:issues).flatten.group_by(&:state)
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
|
|
|
|
2014-06-30 08:54:57 +00:00
|
|
|
def merge_requests
|
2015-11-13 18:20:48 +00:00
|
|
|
@merge_requests ||= milestones.map(&:merge_requests).flatten.group_by(&:state)
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def participants
|
2015-11-13 18:20:48 +00:00
|
|
|
@participants ||= milestones.map(&:participants).flatten.compact.uniq
|
2014-06-27 08:14:57 +00:00
|
|
|
end
|
2014-06-30 10:41:27 +00:00
|
|
|
|
|
|
|
def opened_issues
|
|
|
|
issues.values_at("opened", "reopened").compact.flatten
|
|
|
|
end
|
|
|
|
|
|
|
|
def closed_issues
|
|
|
|
issues['closed']
|
|
|
|
end
|
|
|
|
|
|
|
|
def opened_merge_requests
|
|
|
|
merge_requests.values_at("opened", "reopened").compact.flatten
|
|
|
|
end
|
|
|
|
|
|
|
|
def closed_merge_requests
|
|
|
|
merge_requests.values_at("closed", "merged", "locked").compact.flatten
|
|
|
|
end
|
2014-06-26 08:57:36 +00:00
|
|
|
end
|