execute

in app/services/notes/create_service.rb [5:69]


    def execute
      note = Notes::BuildService.new(project, current_user, params.except(:merge_request_diff_head_sha)).execute

      
      note_valid = Gitlab::GitalyClient.allow_n_plus_1_calls do
        
        
        note.errors.empty? && note.valid?
      end

      return note unless note_valid

      
      
      
      quick_actions_service = QuickActionsService.new(project, current_user)

      if quick_actions_service.supported?(note)
        content, update_params, message = quick_actions_service.execute(note, quick_action_options)

        only_commands = content.empty?

        note.note = content
      end

      note.run_after_commit do
        
        NewNoteWorker.perform_async(note.id)
      end

      note_saved = note.with_transaction_returning_status do
        !only_commands && note.save && note.store_mentions!
      end

      if note_saved
        if note.part_of_discussion? && note.discussion.can_convert_to_discussion?
          note.discussion.convert_to_discussion!(save: true)
        end

        todo_service.new_note(note, current_user)
        clear_noteable_diffs_cache(note)
        Suggestions::CreateService.new(note).execute
        increment_usage_counter(note)

        if Feature.enabled?(:notes_create_service_tracking, project)
          Gitlab::Tracking.event('Notes::CreateService', 'execute', tracking_data_for(note))
        end
      end

      if quick_actions_service.commands_executed_count.to_i > 0
        if update_params.present?
          quick_actions_service.apply_updates(update_params, note)
          note.commands_changes = update_params
        end

        
        
        if only_commands
          note.errors.add(:commands_only, message.presence || _('Failed to apply commands.'))
        end
      end

      note
    end