Welcome to mirror list, hosted at ThFree Co, Russian Federation.

milestone_note.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8ff0503502f302dc29ffde358233a8ecd0e5d29d (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
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

class MilestoneNote < ::Note
  attr_accessor :resource_parent, :event, :milestone

  def self.from_event(event, resource: nil, resource_parent: nil)
    resource ||= event.resource

    attrs = {
        system: true,
        author: event.user,
        created_at: event.created_at,
        noteable: resource,
        milestone: event.milestone,
        event: event,
        system_note_metadata: ::SystemNoteMetadata.new(action: 'milestone'),
        resource_parent: resource_parent
    }

    if resource_parent.is_a?(Project)
      attrs[:project_id] = resource_parent.id
    end

    MilestoneNote.new(attrs)
  end

  def note
    @note ||= note_text
  end

  def note_html
    @note_html ||= Banzai::Renderer.cacheless_render_field(self, :note, { group: group, project: project })
  end

  def project
    resource_parent if resource_parent.is_a?(Project)
  end

  def group
    resource_parent if resource_parent.is_a?(Group)
  end

  private

  def note_text(html: false)
    format = milestone&.group_milestone? ? :name : :iid
    milestone.nil? ? 'removed milestone' : "changed milestone to #{milestone.to_reference(project, format: format)}"
  end
end