Class: Gitlab::Triage::Resource::Milestone

Inherits:
Base
  • Object
show all
Defined in:
lib/gitlab/triage/resource/milestone.rb

Constant Summary collapse

FIELDS =
%i[
  id
  iid
  project_id
  group_id
  title
  description
  state
].freeze
DATE_FIELDS =
%i[
  due_date
  start_date
].freeze
TIME_FIELDS =
%i[
  updated_at
  created_at
].freeze

Constants inherited from Base

Base::CONFIDENTIAL_TEXT, Base::SOURCE_ERROR_MSG

Instance Attribute Summary

Attributes inherited from Base

#parent, #resource

Instance Method Summary collapse

Methods inherited from Base

#build_url, define_field, #expand_resource!, #initialize, #network, #redact_confidential_attributes?, #resource_id, #resource_url, #source, #source_resource, #source_url, #url, #url_opts

Constructor Details

This class inherits a constructor from Gitlab::Triage::Resource::Base

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/gitlab/triage/resource/milestone.rb', line 59

def active?
  state == 'active'
end

#all_activeObject (private)



91
92
93
94
95
96
# File 'lib/gitlab/triage/resource/milestone.rb', line 91

def all_active
  @all_active ||=
    network
      .query_api_cached(url(state: 'active'))
      .map { |milestone| self.class.new(milestone, parent: self) }
end

#all_active_with_start_dateObject (private)



86
87
88
89
# File 'lib/gitlab/triage/resource/milestone.rb', line 86

def all_active_with_start_date
  @all_active_with_start_date ||=
    all_active.select(&:start_date).sort_by(&:start_date)
end

#closed?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/gitlab/triage/resource/milestone.rb', line 63

def closed?
  state == 'closed'
end

#current_indexObject (private)



81
82
83
84
# File 'lib/gitlab/triage/resource/milestone.rb', line 81

def current_index
  all_active_with_start_date
    .index { |milestone| milestone.id == id }
end

#expired?(today = Date.today) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/gitlab/triage/resource/milestone.rb', line 71

def expired?(today = Date.today)
  due_date && due_date < today
end

#in_progress?(today = Date.today) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/gitlab/triage/resource/milestone.rb', line 75

def in_progress?(today = Date.today)
  started?(today) && !expired?(today)
end

#started?(today = Date.today) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/gitlab/triage/resource/milestone.rb', line 67

def started?(today = Date.today)
  start_date && start_date <= today
end

#succObject



53
54
55
56
57
# File 'lib/gitlab/triage/resource/milestone.rb', line 53

def succ
  index = current_index

  all_active_with_start_date[index.succ] if index
end