gitlab-org--gitlab-foss/app/services/notes/create_service.rb

33 lines
806 B
Ruby
Raw Normal View History

2012-07-31 01:32:49 -04:00
module Notes
class CreateService < BaseService
2012-07-31 01:32:49 -04:00
def execute
2014-06-17 15:09:01 -04:00
note = project.notes.new(params)
2012-07-31 01:32:49 -04:00
note.author = current_user
note.system = false
2014-06-17 15:09:01 -04:00
if note.save
notification_service.new_note(note)
2015-11-11 08:12:51 -05:00
# Skip system notes, like status changes and cross-references and awards
unless note.system || note.is_award
2014-06-17 15:09:01 -04:00
event_service.leave_note(note, note.author)
note.create_cross_references!
execute_hooks(note)
2014-06-17 15:09:01 -04:00
end
end
2012-07-31 01:32:49 -04:00
note
end
def hook_data(note)
Gitlab::NoteDataBuilder.build(note, current_user)
end
def execute_hooks(note)
note_data = hook_data(note)
note.project.execute_hooks(note_data, :note_hooks)
note.project.execute_services(note_data, :note_hooks)
end
2012-07-31 01:32:49 -04:00
end
end