BigW Consortium Gitlab

group_milestone.rb 1.79 KB
Newer Older
1
class GroupMilestone
2
  attr_accessor :title, :milestones
3 4
  alias_attribute :name, :title

5 6 7 8 9
  def initialize(title, milestones)
    @title = title
    @milestones = milestones
  end

10
  def safe_title
11
    @title.parameterize
12
  end
13
  
14
  def projects
Marin Jankovski committed
15
    milestones.map { |milestone| milestone.project }
16 17 18
  end

  def issue_count
Marin Jankovski committed
19
    milestones.map { |milestone| milestone.issues.count }.sum
20 21 22
  end

  def merge_requests_count
Marin Jankovski committed
23
    milestones.map { |milestone| milestone.merge_requests.count }.sum
24 25
  end

26
  def open_items_count
Marin Jankovski committed
27
    milestones.map { |milestone| milestone.open_items_count }.sum
28 29
  end

30
  def closed_items_count
Marin Jankovski committed
31
    milestones.map { |milestone| milestone.closed_items_count }.sum
32 33 34
  end

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

  def percent_complete
    ((closed_items_count * 100) / total_items_count).abs
  rescue ZeroDivisionError
41
    0
42
  end
43 44

  def state
Marin Jankovski committed
45
    state = milestones.map { |milestone| milestone.state }
46

47
    if state.count('closed') == state.size
48
      'closed'
49 50
    else
      'active'
51 52
    end
  end
53 54 55 56 57 58 59 60 61

  def active?
    state == 'active'
  end

  def closed?
    state == 'closed'
  end

62
  def issues
63
    @group_issues ||= milestones.map(&:issues).flatten.group_by(&:state)
64 65
  end

66
  def merge_requests
67
    @group_merge_requests ||= milestones.map(&:merge_requests).flatten.group_by(&:state)
68 69 70
  end

  def participants
71
    @group_participants ||= milestones.map(&:participants).flatten.compact.uniq
72
  end
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

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