Commit 72ff7966 authored by Peter Leitzen's avatar Peter Leitzen
Browse files

Move finding autocompletion targets into AutocompleteService

parent 0ac62f61f35c
class Projects::AutocompleteSourcesController < Projects::ApplicationController class Projects::AutocompleteSourcesController < Projects::ApplicationController
before_action :load_autocomplete_service, except: [:members] before_action :load_autocomplete_service
def members def members
render json: ::Projects::ParticipantsService.new(@project, current_user).execute(target) render json: ::Projects::ParticipantsService.new(@project, current_user).execute(target)
...@@ -32,13 +32,6 @@ def load_autocomplete_service ...@@ -32,13 +32,6 @@ def load_autocomplete_service
end end
def target def target
case params[:type]&.downcase @autocomplete_service.target(params[:type], params[:type_id])
when 'issue'
IssuesFinder.new(current_user, project_id: @project.id).find_by(iid: params[:type_id]) || @project.issues.build
when 'mergerequest'
MergeRequestsFinder.new(current_user, project_id: @project.id).find_by(iid: params[:type_id]) || @project.merge_requests.build
when 'commit'
@project.commit(params[:type_id])
end
end end
end end
...@@ -51,5 +51,16 @@ def commands(noteable, type) ...@@ -51,5 +51,16 @@ def commands(noteable, type)
QuickActions::InterpretService.new(project, current_user).available_commands(noteable) QuickActions::InterpretService.new(project, current_user).available_commands(noteable)
end end
def target(type, type_id)
case type&.downcase
when 'issue'
IssuesFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.issues.build
when 'mergerequest'
MergeRequestsFinder.new(current_user, project_id: project.id).find_by(iid: type_id) || project.merge_requests.build
when 'commit'
project.commit(type_id)
end
end
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment