summaryrefslogtreecommitdiff
path: root/app/models/resource_milestone_event.rb
blob: 36068cf508b3a00563ef01538c2e12cc9d06a988 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

class ResourceMilestoneEvent < ResourceEvent
  include IgnorableColumns
  include IssueResourceEvent
  include MergeRequestResourceEvent

  belongs_to :milestone

  validate :exactly_one_issuable

  scope :include_relations, -> { includes(:user, milestone: [:project, :group]) }

  enum action: {
    add: 1,
    remove: 2
  }

  # state is used for issue and merge request states.
  enum state: Issue.available_states.merge(MergeRequest.available_states)

  ignore_columns %i[reference reference_html cached_markdown_version], remove_with: '13.1', remove_after: '2020-06-22'

  def self.issuable_attrs
    %i(issue merge_request).freeze
  end

  def milestone_title
    milestone&.title
  end

  def milestone_parent
    milestone&.parent
  end

  def issuable
    issue || merge_request
  end
end