debian-mirror-gitlab/app/graphql/mutations/ci/runner/update.rb

81 lines
2.4 KiB
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
module Mutations
module Ci
module Runner
class Update < BaseMutation
graphql_name 'RunnerUpdate'
authorize :update_runner
2023-05-27 22:25:52 +05:30
include Mutations::Ci::Runner::CommonMutationArguments
2021-09-04 01:27:46 +05:30
RunnerID = ::Types::GlobalIDType[::Ci::Runner]
argument :id, RunnerID,
required: true,
description: 'ID of the runner to update.'
2021-10-27 15:23:28 +05:30
argument :active, GraphQL::Types::Boolean,
2021-09-04 01:27:46 +05:30
required: false,
2022-04-04 11:22:00 +05:30
description: 'Indicates the runner is allowed to receive jobs.',
deprecated: { reason: :renamed, replacement: 'paused', milestone: '14.8' }
2021-09-04 01:27:46 +05:30
field :runner,
Types::Ci::RunnerType,
null: true,
2021-10-27 15:23:28 +05:30
description: 'Runner after mutation.'
2021-09-04 01:27:46 +05:30
def resolve(id:, **runner_attrs)
runner = authorized_find!(id)
2022-10-11 01:57:18 +05:30
associated_projects_ids = runner_attrs.delete(:associated_projects)
response = { runner: runner, errors: [] }
::Ci::Runner.transaction do
2023-01-13 00:05:48 +05:30
associate_runner_projects(response, runner, associated_projects_ids) unless associated_projects_ids.nil?
2022-10-11 01:57:18 +05:30
update_runner(response, runner, runner_attrs)
2021-09-04 01:27:46 +05:30
end
2022-10-11 01:57:18 +05:30
response
2021-09-04 01:27:46 +05:30
end
def find_object(id)
GitlabSchema.find_by_gid(id)
end
2022-10-11 01:57:18 +05:30
private
def associate_runner_projects(response, runner, associated_project_ids)
unless runner.project_type?
raise Gitlab::Graphql::Errors::ArgumentError,
"associatedProjects must not be specified for '#{runner.runner_type}' scope"
end
result = ::Ci::Runners::SetRunnerAssociatedProjectsService.new(
runner: runner,
current_user: current_user,
project_ids: associated_project_ids
).execute
return if result.success?
2022-11-25 23:54:43 +05:30
response[:runner] = nil
2022-10-11 01:57:18 +05:30
response[:errors] = result.errors
raise ActiveRecord::Rollback
end
def update_runner(response, runner, attrs)
result = ::Ci::Runners::UpdateRunnerService.new(runner).execute(attrs)
return if result.success?
2022-11-25 23:54:43 +05:30
response[:runner] = nil
2022-10-11 01:57:18 +05:30
response[:errors] = result.errors
raise ActiveRecord::Rollback
end
2021-09-04 01:27:46 +05:30
end
end
end
end
2021-09-30 23:02:18 +05:30
Mutations::Ci::Runner::Update.prepend_mod_with('Mutations::Ci::Runner::Update')