gitlab-org--gitlab-foss/app/services/projects/autocomplete_service.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

module Projects
class AutocompleteService < BaseService
def issues
2016-08-12 21:17:18 -04:00
IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
end
def milestones
@project.milestones.active.reorder(due_date: :asc, title: :asc).select([:iid, :title])
end
def merge_requests
2016-08-12 21:17:18 -04:00
MergeRequestsFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
end
2016-05-03 07:07:06 -04:00
def labels
LabelsFinder.new(current_user, project_id: project.id).execute.select([:title, :color])
2016-05-03 07:07:06 -04:00
end
2016-08-12 21:17:18 -04:00
def commands(noteable, type)
noteable ||=
case type
when 'Issue'
@project.issues.build
when 'MergeRequest'
@project.merge_requests.build
end
2016-08-12 21:17:18 -04:00
return [] unless noteable && noteable.is_a?(Issuable)
opts = {
project: project,
issuable: noteable,
current_user: current_user
2016-08-12 21:17:18 -04:00
}
SlashCommands::InterpretService.command_definitions.map do |definition|
next unless definition.available?(opts)
2016-08-12 21:17:18 -04:00
definition.to_h(opts)
end.compact
end
end
end