debian-mirror-gitlab/app/services/notes/create_service.rb

46 lines
1.1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module Notes
class CreateService < BaseService
def execute
note = project.notes.new(params)
note.author = current_user
note.system = false
2015-11-26 14:37:03 +05:30
if contains_emoji_only?(params[:note])
note.is_award = true
note.note = emoji_name(params[:note])
end
2014-09-02 18:07:02 +05:30
if note.save
notification_service.new_note(note)
2015-11-26 14:37:03 +05:30
# Skip system notes, like status changes and cross-references and awards
unless note.system || note.is_award
2014-09-02 18:07:02 +05:30
event_service.leave_note(note, note.author)
2015-10-24 18:46:33 +05:30
note.create_cross_references!
2015-04-26 12:48:37 +05:30
execute_hooks(note)
2014-09-02 18:07:02 +05:30
end
end
note
end
2015-04-26 12:48:37 +05:30
def hook_data(note)
Gitlab::NoteDataBuilder.build(note, current_user)
end
def execute_hooks(note)
note_data = hook_data(note)
2015-09-11 14:41:01 +05:30
note.project.execute_hooks(note_data, :note_hooks)
2015-04-26 12:48:37 +05:30
note.project.execute_services(note_data, :note_hooks)
end
2015-11-26 14:37:03 +05:30
def contains_emoji_only?(note)
note =~ /\A:[-_+[:alnum:]]*:\s?\z/
end
def emoji_name(note)
note.match(/\A:([-_+[:alnum:]]*):\s?/)[1]
end
2014-09-02 18:07:02 +05:30
end
end