Commit 2c3cd97c authored by Alex Kalderimis's avatar Alex Kalderimis

Simplify parameter key checks

This uses set union to verify the parameter suitability for the
more specialized service, and makes the service responsible for
selecting between `assignee_id` and `assignee_ids`.
parent 3f476ea7
......@@ -56,6 +56,13 @@ module MergeRequests
params.fetch(:assignee_ids).first(1)
end
def params
ps = super
# allow either assignee_id or assignee_ids, preferring assignee_id if passed.
{ assignee_ids: ps.key?(:assignee_id) ? Array.wrap(ps[:assignee_id]) : ps[:assignee_ids] }
end
def update_attrs
@attrs ||= { updated_at: Time.current, updated_by: current_user, assignee_ids: assignee_ids }
end
......
......@@ -424,8 +424,7 @@ module API
mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch) if mr_params.has_key?(:remove_source_branch)
mr_params = convert_parameters_from_legacy_format(mr_params)
service = if mr_params.keys == [:assignee_ids] || mr_params.keys == [:assignee_id]
mr_params[:assignee_ids] = Array.wrap(mr_params[:assignee_ids]) if mr_params.key?(:assignee_id)
service = if mr_params.one? && (mr_params.keys & %i[assignee_id assignee_ids]).one?
::MergeRequests::UpdateAssigneesService
else
::MergeRequests::UpdateService
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment