summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/ci/job/artifacts_destroy.rb
blob: c27ab9c4d89bdc85296f0967ea5c8c5931243df3 (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
# 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::DestroyBatchService.new(job.job_artifacts, pick_up_at: Time.current).execute
          {
            job: job,
            destroyed_artifacts_count: result[:destroyed_artifacts_count],
            errors: Array(result[:errors])
          }
        end
      end
    end
  end
end