2014-06-26 04:57:36 -04:00
|
|
|
class GroupMilestone
|
|
|
|
|
|
|
|
def initialize(title, milestones)
|
|
|
|
@title = title
|
|
|
|
@milestones = milestones
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
@title
|
|
|
|
end
|
|
|
|
|
2014-06-27 04:14:57 -04:00
|
|
|
def safe_title
|
2014-06-30 10:18:26 -04:00
|
|
|
@title.parameterize
|
2014-06-27 04:14:57 -04:00
|
|
|
end
|
|
|
|
|
2014-06-26 04:57:36 -04:00
|
|
|
def milestones
|
|
|
|
@milestones
|
|
|
|
end
|
|
|
|
|
2014-06-26 07:32:35 -04:00
|
|
|
def projects
|
2014-06-30 07:27:17 -04:00
|
|
|
milestones.map { |milestone| milestone.project }
|
2014-06-26 04:57:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def issue_count
|
2014-06-30 07:27:17 -04:00
|
|
|
milestones.map { |milestone| milestone.issues.count }.sum
|
2014-06-26 04:57:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_requests_count
|
2014-06-30 07:27:17 -04:00
|
|
|
milestones.map { |milestone| milestone.merge_requests.count }.sum
|
2014-06-26 04:57:36 -04:00
|
|
|
end
|
|
|
|
|
2014-06-27 04:14:57 -04:00
|
|
|
def open_items_count
|
2014-06-30 07:27:17 -04:00
|
|
|
milestones.map { |milestone| milestone.open_items_count }.sum
|
2014-06-27 04:14:57 -04:00
|
|
|
end
|
|
|
|
|
2014-06-26 04:57:36 -04:00
|
|
|
def closed_items_count
|
2014-06-30 07:27:17 -04:00
|
|
|
milestones.map { |milestone| milestone.closed_items_count }.sum
|
2014-06-26 04:57:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def total_items_count
|
2014-06-30 07:27:17 -04:00
|
|
|
milestones.map { |milestone| milestone.total_items_count }.sum
|
2014-06-26 04:57:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def percent_complete
|
|
|
|
((closed_items_count * 100) / total_items_count).abs
|
|
|
|
rescue ZeroDivisionError
|
2015-05-26 14:44:04 -04:00
|
|
|
0
|
2014-06-26 04:57:36 -04:00
|
|
|
end
|
2014-06-26 05:58:40 -04:00
|
|
|
|
|
|
|
def state
|
2014-06-30 07:27:17 -04:00
|
|
|
state = milestones.map { |milestone| milestone.state }
|
2014-06-26 07:32:35 -04:00
|
|
|
|
2014-07-14 09:25:09 -04:00
|
|
|
if state.count('closed') == state.size
|
2014-06-26 05:58:40 -04:00
|
|
|
'closed'
|
2014-07-14 09:25:09 -04:00
|
|
|
else
|
|
|
|
'active'
|
2014-06-26 05:58:40 -04:00
|
|
|
end
|
|
|
|
end
|
2014-06-27 04:14:57 -04:00
|
|
|
|
|
|
|
def active?
|
|
|
|
state == 'active'
|
|
|
|
end
|
|
|
|
|
|
|
|
def closed?
|
|
|
|
state == 'closed'
|
|
|
|
end
|
|
|
|
|
2014-06-30 04:54:57 -04:00
|
|
|
def issues
|
2015-02-05 15:26:57 -05:00
|
|
|
@group_issues ||= milestones.map(&:issues).flatten.group_by(&:state)
|
2014-06-27 04:14:57 -04:00
|
|
|
end
|
|
|
|
|
2014-06-30 04:54:57 -04:00
|
|
|
def merge_requests
|
2015-02-05 15:26:57 -05:00
|
|
|
@group_merge_requests ||= milestones.map(&:merge_requests).flatten.group_by(&:state)
|
2014-06-27 04:14:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def participants
|
2015-02-05 15:26:57 -05:00
|
|
|
@group_participants ||= milestones.map(&:participants).flatten.compact.uniq
|
2014-06-27 04:14:57 -04:00
|
|
|
end
|
2014-06-30 06:41:27 -04: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 04:57:36 -04:00
|
|
|
end
|