debian-mirror-gitlab/app/graphql/mutations/merge_requests/set_labels.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.8 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module Mutations
module MergeRequests
class SetLabels < Base
graphql_name 'MergeRequestSetLabels'
argument :label_ids,
2021-01-29 00:20:46 +05:30
[::Types::GlobalIDType[Label]],
2019-12-26 22:10:19 +05:30
required: true,
description: <<~DESC
2021-10-27 15:23:28 +05:30
Label IDs to set. Replaces existing labels by default.
2019-12-26 22:10:19 +05:30
DESC
argument :operation_mode,
Types::MutationOperationModeEnum,
required: false,
description: <<~DESC
2021-06-08 01:23:25 +05:30
Changes the operation mode. Defaults to REPLACE.
2019-12-26 22:10:19 +05:30
DESC
def resolve(project_path:, iid:, label_ids:, operation_mode: Types::MutationOperationModeEnum.enum[:replace])
merge_request = authorized_find!(project_path: project_path, iid: iid)
project = merge_request.project
2021-01-29 00:20:46 +05:30
# TODO: remove this line when the compatibility layer is removed:
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
label_ids = label_ids.map { |id| ::Types::GlobalIDType[::Label].coerce_isolated_input(id) }
# MergeRequests::UpdateService expects integers
label_ids = label_ids.compact.map(&:model_id)
2019-12-26 22:10:19 +05:30
attribute_name = case operation_mode
when Types::MutationOperationModeEnum.enum[:append]
:add_label_ids
when Types::MutationOperationModeEnum.enum[:remove]
:remove_label_ids
else
:label_ids
end
2021-06-08 01:23:25 +05:30
::MergeRequests::UpdateService.new(project: project, current_user: current_user, params: { attribute_name => label_ids })
2019-12-26 22:10:19 +05:30
.execute(merge_request)
{
merge_request: merge_request,
2020-06-23 00:09:42 +05:30
errors: errors_on_object(merge_request)
2019-12-26 22:10:19 +05:30
}
end
end
end
end