Class: SystemNotes::IncidentsService

Inherits:
BaseService show all
Defined in:
app/services/system_notes/incidents_service.rb

Constant Summary collapse

CHANGED_TEXT =
{
  occurred_at: 'the event time/date on ',
  note: 'the text on ',
  occurred_at_and_note: 'the event time/date and text on '
}.freeze

Instance Attribute Summary

Attributes inherited from BaseService

#author, #noteable, #project

Instance Method Summary collapse

Constructor Details

#initialize(noteable:) ⇒ IncidentsService

Returns a new instance of IncidentsService.



11
12
13
14
# File 'app/services/system_notes/incidents_service.rb', line 11

def initialize(noteable:)
  @noteable = noteable
  @project = noteable.project
end

Instance Method Details

#add_timeline_event(timeline_event) ⇒ Object



16
17
18
19
20
21
# File 'app/services/system_notes/incidents_service.rb', line 16

def add_timeline_event(timeline_event)
  author = timeline_event.author
  body = 'added an incident timeline event'

  create_note(NoteSummary.new(noteable, project, author, body, action: 'timeline_event'))
end

#delete_timeline_event(author) ⇒ Object



30
31
32
33
34
# File 'app/services/system_notes/incidents_service.rb', line 30

def delete_timeline_event(author)
  body = 'deleted an incident timeline event'

  create_note(NoteSummary.new(noteable, project, author, body, action: 'timeline_event'))
end

#edit_timeline_event(timeline_event, author, was_changed:) ⇒ Object



23
24
25
26
27
28
# File 'app/services/system_notes/incidents_service.rb', line 23

def edit_timeline_event(timeline_event, author, was_changed:)
  changed_text = CHANGED_TEXT.fetch(was_changed, '')
  body = "edited #{changed_text}incident timeline event"

  create_note(NoteSummary.new(noteable, project, author, body, action: 'timeline_event'))
end