debian-mirror-gitlab/app/services/projects/autocomplete_service.rb

57 lines
1.6 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Projects
class AutocompleteService < BaseService
2016-06-02 11:05:42 +05:30
def issues
2016-09-13 17:45:13 +05:30
IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
2015-04-26 12:48:37 +05:30
end
2016-06-02 11:05:42 +05:30
def milestones
2017-09-10 17:25:29 +05:30
finder_params = {
project_ids: [@project.id],
state: :active,
order: { due_date: :asc, title: :asc }
}
finder_params[:group_ids] = [@project.group.id] if @project.group
MilestonesFinder.new(finder_params).execute.select([:iid, :title])
2015-04-26 12:48:37 +05:30
end
def merge_requests
2016-09-13 17:45:13 +05:30
MergeRequestsFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title])
2015-04-26 12:48:37 +05:30
end
2016-06-22 15:30:34 +05:30
2018-03-17 18:26:18 +05:30
def labels(target = nil)
labels = LabelsFinder.new(current_user, project_id: project.id).execute.select([:color, :title])
return labels unless target&.respond_to?(:labels)
issuable_label_titles = target.labels.pluck(:title)
if issuable_label_titles
labels = labels.as_json(only: [:title, :color])
issuable_label_titles.each do |issuable_label_title|
found_label = labels.find { |label| label['title'] == issuable_label_title }
found_label[:set] = true if found_label
end
end
labels
2016-06-22 15:30:34 +05:30
end
2016-09-13 17:45:13 +05:30
def commands(noteable, type)
noteable ||=
case type
when 'Issue'
@project.issues.build
when 'MergeRequest'
@project.merge_requests.build
end
2018-03-17 18:26:18 +05:30
return [] unless noteable&.is_a?(Issuable)
2016-09-13 17:45:13 +05:30
2018-03-27 19:54:05 +05:30
QuickActions::InterpretService.new(project, current_user).available_commands(noteable)
2016-09-13 17:45:13 +05:30
end
2015-04-26 12:48:37 +05:30
end
end