2015-01-22 20:51:35 -05:00
|
|
|
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])
|
2015-01-22 20:51:35 -05:00
|
|
|
end
|
|
|
|
|
2016-04-04 22:37:50 -04:00
|
|
|
def milestones
|
2016-04-05 20:43:26 -04:00
|
|
|
@project.milestones.active.reorder(due_date: :asc, title: :asc).select([:iid, :title])
|
2016-04-04 22:37:50 -04:00
|
|
|
end
|
|
|
|
|
2015-01-22 20:51:35 -05:00
|
|
|
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])
|
2015-01-22 20:51:35 -05:00
|
|
|
end
|
2016-05-03 07:07:06 -04:00
|
|
|
|
|
|
|
def labels
|
2016-11-17 04:39:23 -05:00
|
|
|
LabelsFinder.new(current_user, project_id: project.id).execute.select([:title, :color])
|
2016-05-03 07:07:06 -04:00
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
|
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 05:19:29 -04:00
|
|
|
|
2016-08-12 21:17:18 -04:00
|
|
|
return [] unless noteable && noteable.is_a?(Issuable)
|
|
|
|
|
|
|
|
opts = {
|
2016-08-12 05:19:29 -04:00
|
|
|
project: project,
|
2016-08-16 20:59:55 -04:00
|
|
|
issuable: noteable,
|
2016-08-10 11:51:01 -04:00
|
|
|
current_user: current_user
|
2016-08-12 21:17:18 -04:00
|
|
|
}
|
2017-05-31 01:50:53 -04:00
|
|
|
QuickActions::InterpretService.command_definitions.map do |definition|
|
2016-08-12 21:17:18 -04:00
|
|
|
next unless definition.available?(opts)
|
2016-08-10 11:51:01 -04:00
|
|
|
|
2016-08-12 21:17:18 -04:00
|
|
|
definition.to_h(opts)
|
|
|
|
end.compact
|
2016-06-30 11:34:19 -04:00
|
|
|
end
|
2015-01-22 20:51:35 -05:00
|
|
|
end
|
|
|
|
end
|