summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/ci/job/play.rb
blob: 8bb69119a4465e8cff68749d5afa41dbc0dbd01d (plain)
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
# frozen_string_literal: true

module Mutations
  module Ci
    module Job
      class Play < Base
        graphql_name 'JobPlay'

        field :job,
              Types::Ci::JobType,
              null: true,
              description: 'Job after the mutation.'

        argument :variables, [::Types::Ci::VariableInputType],
                 required: false,
                 default_value: [],
                 replace_null_with_default: true,
                 description: 'Variables to use when playing a manual job.'

        authorize :update_build

        def resolve(id:, variables:)
          job = authorized_find!(id: id)
          project = job.project
          variables = variables.map(&:to_h)

          ::Ci::PlayBuildService.new(project, current_user).execute(job, variables)

          {
            job: job,
            errors: errors_on_object(job)
          }
        end
      end
    end
  end
end