2019-03-21 12:01:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Helpers
|
|
|
|
module IssuesHelpers
|
2019-05-29 06:28:11 -04:00
|
|
|
extend Grape::API::Helpers
|
|
|
|
|
2020-11-05 22:09:19 -05:00
|
|
|
params :negatable_issue_filter_params_ee do
|
|
|
|
end
|
|
|
|
|
2019-05-29 06:28:11 -04:00
|
|
|
params :optional_issue_params_ee do
|
|
|
|
end
|
|
|
|
|
2021-03-08 16:09:45 -05:00
|
|
|
params :issues_stats_params_ee do
|
2019-09-17 08:06:48 -04:00
|
|
|
end
|
|
|
|
|
2019-03-21 12:01:08 -04:00
|
|
|
def self.update_params_at_least_one_of
|
|
|
|
[
|
|
|
|
:assignee_id,
|
|
|
|
:assignee_ids,
|
|
|
|
:confidential,
|
|
|
|
:created_at,
|
|
|
|
:description,
|
|
|
|
:discussion_locked,
|
|
|
|
:due_date,
|
|
|
|
:labels,
|
2020-05-20 17:09:09 -04:00
|
|
|
:add_labels,
|
|
|
|
:remove_labels,
|
2019-03-21 12:01:08 -04:00
|
|
|
:milestone_id,
|
|
|
|
:state_event,
|
2021-05-05 14:10:31 -04:00
|
|
|
:title,
|
|
|
|
:issue_type
|
2019-03-21 12:01:08 -04:00
|
|
|
]
|
|
|
|
end
|
2019-04-08 07:17:22 -04:00
|
|
|
|
2019-08-15 06:56:33 -04:00
|
|
|
def self.sort_options
|
2021-09-09 05:11:16 -04:00
|
|
|
%w[
|
|
|
|
created_at
|
|
|
|
due_date
|
|
|
|
label_priority
|
|
|
|
milestone_due
|
|
|
|
popularity
|
|
|
|
priority
|
|
|
|
relative_position
|
|
|
|
title
|
|
|
|
updated_at
|
|
|
|
]
|
2019-08-15 06:56:33 -04:00
|
|
|
end
|
|
|
|
|
2019-04-08 07:17:22 -04:00
|
|
|
def issue_finder(args = {})
|
|
|
|
args = declared_params.merge(args)
|
|
|
|
|
|
|
|
args.delete(:id)
|
2019-09-17 08:06:48 -04:00
|
|
|
args[:not] ||= {}
|
2019-04-08 07:17:22 -04:00
|
|
|
args[:milestone_title] ||= args.delete(:milestone)
|
2021-09-02 05:11:35 -04:00
|
|
|
args[:milestone_wildcard_id] ||= args.delete(:milestone_id)
|
|
|
|
args[:not][:milestone_title] ||= args[:not].delete(:milestone)
|
|
|
|
args[:not][:milestone_wildcard_id] ||= args[:not].delete(:milestone_id)
|
2019-04-08 07:17:22 -04:00
|
|
|
args[:label_name] ||= args.delete(:labels)
|
2021-09-02 05:11:35 -04:00
|
|
|
args[:not][:label_name] ||= args[:not].delete(:labels)
|
2019-04-08 07:17:22 -04:00
|
|
|
args[:scope] = args[:scope].underscore if args[:scope]
|
2019-08-15 06:56:33 -04:00
|
|
|
args[:sort] = "#{args[:order_by]}_#{args[:sort]}"
|
2021-05-05 14:10:31 -04:00
|
|
|
args[:issue_types] ||= args.delete(:issue_type)
|
2019-04-08 07:17:22 -04:00
|
|
|
|
|
|
|
IssuesFinder.new(current_user, args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_issues(args = {})
|
|
|
|
finder = issue_finder(args)
|
2019-08-15 06:56:33 -04:00
|
|
|
finder.execute.with_api_entity_associations
|
2019-04-08 07:17:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def issues_statistics(args = {})
|
|
|
|
finder = issue_finder(args)
|
|
|
|
counter = Gitlab::IssuablesCountForState.new(finder)
|
|
|
|
|
|
|
|
{
|
|
|
|
statistics: {
|
|
|
|
counts: {
|
|
|
|
all: counter[:all],
|
|
|
|
closed: counter[:closed],
|
|
|
|
opened: counter[:opened]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2019-03-21 12:01:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
API::Helpers::IssuesHelpers.prepend_mod_with('API::Helpers::IssuesHelpers')
|