BigW Consortium Gitlab

group_milestone.rb 1.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
class GroupMilestone

  def initialize(title, milestones)
    @title = title
    @milestones = milestones
  end

  def title
    @title
  end

12
  def safe_title
13
    @title.parameterize
14 15
  end

16 17 18 19
  def milestones
    @milestones
  end

20
  def projects
Marin Jankovski committed
21
    milestones.map { |milestone| milestone.project }
22 23 24
  end

  def issue_count
Marin Jankovski committed
25
    milestones.map { |milestone| milestone.issues.count }.sum
26 27 28
  end

  def merge_requests_count
Marin Jankovski committed
29
    milestones.map { |milestone| milestone.merge_requests.count }.sum
30 31
  end

32
  def open_items_count
Marin Jankovski committed
33
    milestones.map { |milestone| milestone.open_items_count }.sum
34 35
  end

36
  def closed_items_count
Marin Jankovski committed
37
    milestones.map { |milestone| milestone.closed_items_count }.sum
38 39 40
  end

  def total_items_count
Marin Jankovski committed
41
    milestones.map { |milestone| milestone.total_items_count }.sum
42 43 44 45 46 47 48
  end

  def percent_complete
    ((closed_items_count * 100) / total_items_count).abs
  rescue ZeroDivisionError
    100
  end
49 50

  def state
Marin Jankovski committed
51
    state = milestones.map { |milestone| milestone.state }
52

53
    if state.count('closed') == state.size
54
      'closed'
55 56
    else
      'active'
57 58
    end
  end
59 60 61 62 63 64 65 66 67

  def active?
    state == 'active'
  end

  def closed?
    state == 'closed'
  end

68
  def issues
Marin Jankovski committed
69
    @group_issues ||= milestones.map { |milestone| milestone.issues }.flatten.group_by(&:state)
70 71
  end

72
  def merge_requests
Marin Jankovski committed
73
    @group_merge_requests ||= milestones.map { |milestone| milestone.merge_requests }.flatten.group_by(&:state)
74 75 76
  end

  def participants
Marin Jankovski committed
77
    milestones.map { |milestone| milestone.participants.uniq }.reject(&:empty?).flatten
78
  end
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

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