Class: Mutations::Projects::TextReplace

Inherits:
BaseMutation
  • Object
show all
Includes:
FindsProject
Defined in:
app/graphql/mutations/projects/text_replace.rb

Constant Summary collapse

UNSUPPORTED_REPLACEMENT_PREFIX =
%r{(?:regex|glob):}
SUPPORTED_REPLACEMENT_PREFIX =
%r{literal:}
EMPTY_REPLACEMENTS_ARG_ERROR =
<<~ERROR
  Argument 'replacements' on InputObject 'projectTextReplaceInput' is required. Expected type [String!]!
ERROR
UNSUPPORTED_REPLACEMENTS_ARG_ERROR =
<<~ERROR
  Argument 'replacements' on InputObject 'projectTextReplaceInput' does not support 'regex:' or 'glob:' values.
ERROR

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 inherited from BaseMutation

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

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

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

Instance Method Details

#resolve(project_path:, replacements:) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'app/graphql/mutations/projects/text_replace.rb', line 40

def resolve(project_path:, replacements:)
  project = authorized_find!(project_path)

  result = ::Repositories::RewriteHistoryService.new(project, current_user)
             .async_execute(redactions: replacements)

  return { errors: result.errors } if result.error?

  { errors: [] }
end