debian-mirror-gitlab/app/models/concerns/ci/artifactable.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.2 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
module Ci
module Artifactable
extend ActiveSupport::Concern
2021-04-29 21:17:54 +05:30
include ObjectStorable
2020-11-24 15:15:51 +05:30
2021-04-29 21:17:54 +05:30
STORE_COLUMN = :file_store
NotSupportedAdapterError = Class.new(StandardError)
2020-10-24 23:57:45 +05:30
FILE_FORMAT_ADAPTERS = {
gzip: Gitlab::Ci::Build::Artifacts::Adapters::GzipStream,
raw: Gitlab::Ci::Build::Artifacts::Adapters::RawStream
}.freeze
included do
enum file_format: {
raw: 1,
zip: 2,
gzip: 3
}, _suffix: true
2020-11-24 15:15:51 +05:30
2021-03-08 18:12:59 +05:30
scope :expired_before, -> (timestamp) { where(arel_table[:expire_at].lt(timestamp)) }
2022-07-23 23:45:48 +05:30
scope :expired, -> { expired_before(Time.current) }
2021-04-29 21:17:54 +05:30
scope :project_id_in, ->(ids) { where(project_id: ids) }
2020-11-24 15:15:51 +05:30
end
def each_blob(&blk)
unless file_format_adapter_class
raise NotSupportedAdapterError, 'This file format requires a dedicated adapter'
end
2022-08-13 15:12:31 +05:30
::Gitlab::ApplicationContext.push(artifact: file.model)
2020-11-24 15:15:51 +05:30
file.open do |stream|
file_format_adapter_class.new(stream).each_blob(&blk)
end
end
private
def file_format_adapter_class
FILE_FORMAT_ADAPTERS[file_format.to_sym]
2020-10-24 23:57:45 +05:30
end
end
end
2021-04-29 21:17:54 +05:30
2021-06-08 01:23:25 +05:30
Ci::Artifactable.prepend_mod