blob: 477c999eff45ec13d04c46b724b1838a577850a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
module Projects
class AutocompleteService < BaseService
def issues
@project.issues.visible_to_user(current_user).opened.select([:iid, :title])
end
def milestones
@project.milestones.active.reorder(due_date: :asc, title: :asc).select([:iid, :title])
end
def merge_requests
@project.merge_requests.opened.select([:iid, :title])
end
def labels
@project.labels.select([:title, :color])
end
def commands
# We don't return commands when editing an issue or merge request
# This should be improved by not enabling autocomplete at the JS-level
# following this suggestion: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5021#note_13837384
return [] if !target || %w[edit update].include?(params[:action_name])
SlashCommands::InterpretService.command_definitions(
project: project,
noteable: target,
current_user: current_user
)
end
private
def target
@target ||= begin
noteable_id = params[:type_id]
case params[:type]
when 'Issue'
IssuesFinder.new(current_user, project_id: project.id, state: 'all').
execute.find_or_initialize_by(iid: noteable_id)
when 'MergeRequest'
MergeRequestsFinder.new(current_user, project_id: project.id, state: 'all').
execute.find_or_initialize_by(iid: noteable_id)
else
nil
end
end
end
end
end
|