Class: Mutations::Issues::Create

Inherits:
BaseMutation
  • Object
show all
Includes:
FindsProject, CommonMutationArguments, SpamProtection
Defined in:
app/graphql/mutations/issues/create.rb

Constant Summary

Constants included from SpamProtection

SpamProtection::NEEDS_CAPTCHA_RESPONSE_MESSAGE, SpamProtection::NeedsCaptchaResponseError, SpamProtection::SPAM_DISALLOWED_MESSAGE, SpamProtection::SpamActionError, SpamProtection::SpamDisallowedError

Constants inherited from BaseMutation

BaseMutation::ERROR_MESSAGE

Constants included from Gitlab::Graphql::Authorize::AuthorizeResource

Gitlab::Graphql::Authorize::AuthorizeResource::ConfigurationError, Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR

Instance Method Summary collapse

Methods included from Spam::Concerns::HasSpamActionResponseFields

#spam_action_response_fields

Methods inherited from BaseMutation

#api_user?, authorization, authorized?, authorizes_object?, #current_user, #errors_on_object, #load_application_object, #read_only?, #unauthorized_object

Methods included from Gitlab::Graphql::Authorize::AuthorizeResource

#authorize!, #authorized_find!, #authorized_resource?, #find_object, #raise_resource_not_available_error!

Instance Method Details

#ready?(**args) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/graphql/mutations/issues/create.rb', line 67

def ready?(**args)
  if args.slice(*mutually_exclusive_label_args).size > 1
    arg_str = mutually_exclusive_label_args.map { |x| x.to_s.camelize(:lower) }.join(' or ')
    raise Gitlab::Graphql::Errors::ArgumentError, "one and only one of #{arg_str} is required."
  end

  if args[:discussion_to_resolve].present? && args[:merge_request_to_resolve_discussions_of].blank?
    raise Gitlab::Graphql::Errors::ArgumentError,
          'to resolve a discussion please also provide `merge_request_to_resolve_discussions_of` parameter'
  end

  super
end

#resolve(project_path:, **attributes) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/graphql/mutations/issues/create.rb', line 81

def resolve(project_path:, **attributes)
  project = authorized_find!(project_path)
  params = build_create_issue_params(attributes.merge(author_id: current_user.id), project)
  result = ::Issues::CreateService.new(container: project, current_user: current_user, params: params).execute

  check_spam_action_response!(result[:issue]) if result[:issue]

  {
    issue: result.success? ? result[:issue] : nil,
    errors: result.errors
  }
end