1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# frozen_string_literal: true
module Mutations
module Ci
module Runner
class Update < BaseMutation
graphql_name 'RunnerUpdate'
authorize :update_runner
include Mutations::Ci::Runner::CommonMutationArguments
RunnerID = ::Types::GlobalIDType[::Ci::Runner]
argument :id, RunnerID,
required: true,
description: 'ID of the runner to update.'
argument :active, GraphQL::Types::Boolean,
required: false,
description: 'Indicates the runner is allowed to receive jobs.',
deprecated: { reason: :renamed, replacement: 'paused', milestone: '14.8' }
field :runner,
Types::Ci::RunnerType,
null: true,
description: 'Runner after mutation.'
def resolve(id:, **runner_attrs)
runner = authorized_find!(id)
associated_projects_ids = runner_attrs.delete(:associated_projects)
response = { runner: runner, errors: [] }
::Ci::Runner.transaction do
associate_runner_projects(response, runner, associated_projects_ids) unless associated_projects_ids.nil?
update_runner(response, runner, runner_attrs)
end
response
end
def find_object(id)
GitlabSchema.find_by_gid(id)
end
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?
response[:runner] = nil
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?
response[:runner] = nil
response[:errors] = result.errors
raise ActiveRecord::Rollback
end
end
end
end
end
Mutations::Ci::Runner::Update.prepend_mod_with('Mutations::Ci::Runner::Update')
|