Class: Mutations::Ci::Runner::Create

Inherits:
BaseMutation
  • Object
show all
Includes:
CommonMutationArguments
Defined in:
app/graphql/mutations/ci/runner/create.rb

Constant Summary

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, 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?, #raise_resource_not_available_error!

Instance Method Details

#ready?(**args) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/graphql/mutations/ci/runner/create.rb', line 30

def ready?(**args)
  case args[:runner_type]
  when 'group_type'
    raise Gitlab::Graphql::Errors::ArgumentError, '`group_id` is missing' unless args[:group_id].present?
  when 'project_type'
    raise Gitlab::Graphql::Errors::ArgumentError, '`project_id` is missing' unless args[:project_id].present?
  end

  parse_gid(**args)

  super
end

#resolve(**args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/graphql/mutations/ci/runner/create.rb', line 43

def resolve(**args)
  case args[:runner_type]
  when 'group_type', 'project_type'
    args[:scope] = authorized_find!(**args)
    args.except!(:group_id, :project_id)
  else
    raise_resource_not_available_error! unless current_user.can?(:create_instance_runner)
  end

  response = { runner: nil, errors: [] }
  result = ::Ci::Runners::CreateRunnerService.new(user: current_user, params: args).execute

  if result.success?
    response[:runner] = result.payload[:runner]
  else
    response[:errors] = result.errors
  end

  response
end