2015-01-23 01:51:35 +00:00
|
|
|
module Projects
|
|
|
|
class AutocompleteService < BaseService
|
|
|
|
def issues
|
2016-08-13 01:17:18 +00:00
|
|
|
IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
|
2015-01-23 01:51:35 +00:00
|
|
|
end
|
|
|
|
|
2016-04-05 02:37:50 +00:00
|
|
|
def milestones
|
2016-04-06 00:43:26 +00:00
|
|
|
@project.milestones.active.reorder(due_date: :asc, title: :asc).select([:iid, :title])
|
2016-04-05 02:37:50 +00:00
|
|
|
end
|
|
|
|
|
2015-01-23 01:51:35 +00:00
|
|
|
def merge_requests
|
2016-08-13 01:17:18 +00:00
|
|
|
MergeRequestsFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
|
2015-01-23 01:51:35 +00:00
|
|
|
end
|
2016-05-03 11:07:06 +00:00
|
|
|
|
|
|
|
def labels
|
2016-11-17 09:39:23 +00:00
|
|
|
LabelsFinder.new(current_user, project_id: project.id).execute.select([:title, :color])
|
2016-05-03 11:07:06 +00:00
|
|
|
end
|
2016-06-30 15:34:19 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
def commands(noteable, type)
|
|
|
|
noteable ||=
|
|
|
|
case type
|
|
|
|
when 'Issue'
|
|
|
|
@project.issues.build
|
|
|
|
when 'MergeRequest'
|
|
|
|
@project.merge_requests.build
|
|
|
|
end
|
2016-08-12 09:19:29 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
return [] unless noteable && noteable.is_a?(Issuable)
|
|
|
|
|
|
|
|
opts = {
|
2016-08-12 09:19:29 +00:00
|
|
|
project: project,
|
2016-08-17 00:59:55 +00:00
|
|
|
issuable: noteable,
|
2016-08-10 15:51:01 +00:00
|
|
|
current_user: current_user
|
2016-08-13 01:17:18 +00:00
|
|
|
}
|
|
|
|
SlashCommands::InterpretService.command_definitions.map do |definition|
|
|
|
|
next unless definition.available?(opts)
|
2016-08-10 15:51:01 +00:00
|
|
|
|
2016-08-13 01:17:18 +00:00
|
|
|
definition.to_h(opts)
|
|
|
|
end.compact
|
2016-06-30 15:34:19 +00:00
|
|
|
end
|
2015-01-23 01:51:35 +00:00
|
|
|
end
|
|
|
|
end
|