Welcome to mirror list, hosted at ThFree Co, Russian Federation.

artifacts_destroy.rb « job « ci « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34c58fc1240c4a6d5b407c79c03bedb8e9c34f4b (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
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Mutations
  module Ci
    module Job
      class ArtifactsDestroy < Base
        graphql_name 'JobArtifactsDestroy'

        authorize :destroy_artifacts

        field :job,
              Types::Ci::JobType,
              null: true,
              description: 'Job with artifacts to be deleted.'

        field :destroyed_artifacts_count,
              GraphQL::Types::Int,
              null: false,
              description: 'Number of artifacts deleted.'

        def find_object(id: )
          GlobalID::Locator.locate(id)
        end

        def resolve(id:)
          job = authorized_find!(id: id)

          result = ::Ci::JobArtifacts::DeleteService.new(job).execute

          if result.success?
            {
              job: job,
              destroyed_artifacts_count: result.payload[:destroyed_artifacts_count],
              errors: Array(result.payload[:errors])
            }
          else
            {
              job: job,
              destroyed_artifacts_count: 0,
              errors: Array(result.message)
            }
          end
        end
      end
    end
  end
end