2020-02-18 04:09:24 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Issues
|
|
|
|
class Update < Base
|
|
|
|
graphql_name 'UpdateIssue'
|
|
|
|
|
2020-10-14 08:08:58 -04:00
|
|
|
include CommonMutationArguments
|
2020-02-21 16:08:57 -05:00
|
|
|
|
2021-07-22 17:09:40 -04:00
|
|
|
argument :title, GraphQL::Types::String,
|
2020-07-27 17:09:16 -04:00
|
|
|
required: false,
|
2020-10-14 08:08:58 -04:00
|
|
|
description: copy_field_description(Types::IssueType, :title)
|
2020-07-27 17:09:16 -04:00
|
|
|
|
2021-07-22 17:09:40 -04:00
|
|
|
argument :milestone_id, GraphQL::Types::ID, # rubocop: disable Graphql/IDType
|
2020-07-29 08:09:45 -04:00
|
|
|
required: false,
|
2021-08-11 23:10:11 -04:00
|
|
|
description: 'ID of the milestone to assign to the issue. On update milestone will be removed if set to null.'
|
2020-07-29 08:09:45 -04:00
|
|
|
|
2021-07-22 17:09:40 -04:00
|
|
|
argument :add_label_ids, [GraphQL::Types::ID],
|
2020-07-29 08:09:45 -04:00
|
|
|
required: false,
|
2021-08-11 23:10:11 -04:00
|
|
|
description: 'IDs of labels to be added to the issue.'
|
2020-07-29 08:09:45 -04:00
|
|
|
|
2021-07-22 17:09:40 -04:00
|
|
|
argument :remove_label_ids, [GraphQL::Types::ID],
|
2020-08-07 17:10:07 -04:00
|
|
|
required: false,
|
2021-08-11 23:10:11 -04:00
|
|
|
description: 'IDs of labels to be removed from the issue.'
|
2020-08-07 17:10:07 -04:00
|
|
|
|
2021-07-29 11:09:48 -04:00
|
|
|
argument :label_ids, [GraphQL::Types::ID],
|
|
|
|
required: false,
|
2021-08-11 23:10:11 -04:00
|
|
|
description: 'IDs of labels to be set. Replaces existing issue labels.'
|
2021-07-29 11:09:48 -04:00
|
|
|
|
2020-10-06 05:08:32 -04:00
|
|
|
argument :state_event, Types::IssueStateEventEnum,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: 'Close or reopen an issue.',
|
2020-10-06 05:08:32 -04:00
|
|
|
required: false
|
|
|
|
|
2020-02-18 04:09:24 -05:00
|
|
|
def resolve(project_path:, iid:, **args)
|
|
|
|
issue = authorized_find!(project_path: project_path, iid: iid)
|
|
|
|
project = issue.project
|
|
|
|
|
2021-07-29 11:09:48 -04:00
|
|
|
args = parse_arguments(args)
|
|
|
|
|
2021-06-21 08:07:45 -04:00
|
|
|
spam_params = ::Spam::SpamParams.new_from_request(request: context[:request])
|
|
|
|
::Issues::UpdateService.new(project: project, current_user: current_user, params: args, spam_params: spam_params).execute(issue)
|
2020-02-18 04:09:24 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
issue: issue,
|
2020-05-20 08:07:52 -04:00
|
|
|
errors: errors_on_object(issue)
|
2020-02-18 04:09:24 -05:00
|
|
|
}
|
|
|
|
end
|
2021-07-29 11:09:48 -04:00
|
|
|
|
|
|
|
def ready?(label_ids: [], add_label_ids: [], remove_label_ids: [], **args)
|
|
|
|
if label_ids.any? && (add_label_ids.any? || remove_label_ids.any?)
|
|
|
|
raise Gitlab::Graphql::Errors::ArgumentError, 'labelIds is mutually exclusive with any of addLabelIds or removeLabelIds'
|
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parse_arguments(args)
|
|
|
|
args[:add_label_ids] = parse_label_ids(args[:add_label_ids])
|
|
|
|
args[:remove_label_ids] = parse_label_ids(args[:remove_label_ids])
|
|
|
|
args[:label_ids] = parse_label_ids(args[:label_ids])
|
|
|
|
|
|
|
|
args
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_label_ids(ids)
|
|
|
|
ids&.map do |gid|
|
|
|
|
GitlabSchema.parse_gid(gid, expected_type: ::Label).model_id
|
|
|
|
rescue Gitlab::Graphql::Errors::ArgumentError
|
|
|
|
gid
|
|
|
|
end
|
|
|
|
end
|
2020-02-18 04:09:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Mutations::Issues::Update.prepend_mod_with('Mutations::Issues::Update')
|