debian-mirror-gitlab/app/graphql/mutations/issues/update.rb

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

79 lines
2.6 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module Mutations
module Issues
class Update < Base
graphql_name 'UpdateIssue'
2021-01-03 14:25:43 +05:30
include CommonMutationArguments
2020-04-08 14:13:33 +05:30
2021-10-27 15:23:28 +05:30
argument :title, GraphQL::Types::String,
2020-04-08 14:13:33 +05:30
required: false,
2021-01-03 14:25:43 +05:30
description: copy_field_description(Types::IssueType, :title)
2020-03-13 15:44:24 +05:30
2021-10-27 15:23:28 +05:30
argument :milestone_id, GraphQL::Types::ID, # rubocop: disable Graphql/IDType
2020-10-24 23:57:45 +05:30
required: false,
2021-10-27 15:23:28 +05:30
description: 'ID of the milestone to assign to the issue. On update milestone will be removed if set to null.'
2020-10-24 23:57:45 +05:30
2021-10-27 15:23:28 +05:30
argument :add_label_ids, [GraphQL::Types::ID],
2020-10-24 23:57:45 +05:30
required: false,
2021-10-27 15:23:28 +05:30
description: 'IDs of labels to be added to the issue.'
2020-10-24 23:57:45 +05:30
2021-10-27 15:23:28 +05:30
argument :remove_label_ids, [GraphQL::Types::ID],
2020-10-24 23:57:45 +05:30
required: false,
2021-10-27 15:23:28 +05:30
description: 'IDs of labels to be removed from the issue.'
argument :label_ids, [GraphQL::Types::ID],
required: false,
description: 'IDs of labels to be set. Replaces existing issue labels.'
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
argument :state_event, Types::IssueStateEventEnum,
2021-03-08 18:12:59 +05:30
description: 'Close or reopen an issue.',
2021-01-03 14:25:43 +05:30
required: false
2020-10-24 23:57:45 +05:30
2020-03-13 15:44:24 +05:30
def resolve(project_path:, iid:, **args)
issue = authorized_find!(project_path: project_path, iid: iid)
project = issue.project
2021-10-27 15:23:28 +05:30
args = parse_arguments(args)
2021-09-30 23:02:18 +05:30
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-03-13 15:44:24 +05:30
{
issue: issue,
2020-06-23 00:09:42 +05:30
errors: errors_on_object(issue)
2020-03-13 15:44:24 +05:30
}
end
2021-10-27 15:23:28 +05:30
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-03-13 15:44:24 +05:30
end
end
end
2021-06-08 01:23:25 +05:30
Mutations::Issues::Update.prepend_mod_with('Mutations::Issues::Update')