debian-mirror-gitlab/app/models/global_milestone.rb

131 lines
2.5 KiB
Ruby
Raw Normal View History

2015-11-26 14:37:03 +05:30
class GlobalMilestone
2015-10-24 18:46:33 +05:30
attr_accessor :title, :milestones
alias_attribute :name, :title
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
def self.build_collection(milestones)
milestones = milestones.group_by(&:title)
milestones.map do |title, milestones|
new(title, milestones)
end
end
2014-09-02 18:07:02 +05:30
def initialize(title, milestones)
@title = title
@milestones = milestones
end
def safe_title
@title.to_slug.normalize.to_s
2015-12-23 02:04:40 +05:30
end
def expired?
if due_date
due_date.past?
else
false
end
2014-09-02 18:07:02 +05:30
end
2015-11-26 14:37:03 +05:30
2014-09-02 18:07:02 +05:30
def projects
milestones.map { |milestone| milestone.project }
end
def issue_count
milestones.map { |milestone| milestone.issues.count }.sum
end
def merge_requests_count
milestones.map { |milestone| milestone.merge_requests.count }.sum
end
def open_items_count
milestones.map { |milestone| milestone.open_items_count }.sum
end
def closed_items_count
milestones.map { |milestone| milestone.closed_items_count }.sum
end
def total_items_count
milestones.map { |milestone| milestone.total_items_count }.sum
end
def percent_complete
((closed_items_count * 100) / total_items_count).abs
rescue ZeroDivisionError
2015-09-11 14:41:01 +05:30
0
2014-09-02 18:07:02 +05:30
end
def state
state = milestones.map { |milestone| milestone.state }
if state.count('closed') == state.size
'closed'
else
'active'
end
end
def active?
state == 'active'
end
def closed?
state == 'closed'
end
def issues
2015-11-26 14:37:03 +05:30
@issues ||= milestones.map(&:issues).flatten.group_by(&:state)
2014-09-02 18:07:02 +05:30
end
def merge_requests
2015-11-26 14:37:03 +05:30
@merge_requests ||= milestones.map(&:merge_requests).flatten.group_by(&:state)
2014-09-02 18:07:02 +05:30
end
def participants
2015-11-26 14:37:03 +05:30
@participants ||= milestones.map(&:participants).flatten.compact.uniq
2014-09-02 18:07:02 +05:30
end
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
2015-11-26 14:37:03 +05:30
def complete?
total_items_count == closed_items_count
end
2015-12-23 02:04:40 +05:30
def due_date
return @due_date if defined?(@due_date)
@due_date =
if @milestones.all? { |x| x.due_date == @milestones.first.due_date }
@milestones.first.due_date
else
nil
end
end
def expires_at
if due_date
if due_date.past?
"expired on #{due_date.to_s(:medium)}"
2015-12-23 02:04:40 +05:30
else
"expires on #{due_date.to_s(:medium)}"
2015-12-23 02:04:40 +05:30
end
end
end
2014-09-02 18:07:02 +05:30
end