debian-mirror-gitlab/app/models/concerns/artifact_migratable.rb

59 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
# Adapter class to unify the interface between mounted uploaders and the
# Ci::Artifact model
# Meant to be prepended so the interface can stay the same
module ArtifactMigratable
def artifacts_file
job_artifacts_archive&.file || legacy_artifacts_file
end
def artifacts_metadata
job_artifacts_metadata&.file || legacy_artifacts_metadata
end
def artifacts?
2019-05-18 00:54:41 +05:30
!artifacts_expired? && artifacts_file&.exists?
2018-03-17 18:26:18 +05:30
end
def artifacts_metadata?
artifacts? && artifacts_metadata.exists?
end
def artifacts_file_changed?
job_artifacts_archive&.file_changed? || attribute_changed?(:artifacts_file)
end
def remove_artifacts_file!
if job_artifacts_archive
job_artifacts_archive.destroy
else
remove_legacy_artifacts_file!
end
end
def remove_artifacts_metadata!
if job_artifacts_metadata
job_artifacts_metadata.destroy
else
remove_legacy_artifacts_metadata!
end
end
def artifacts_size
read_attribute(:artifacts_size).to_i + job_artifacts.sum(:size).to_i
end
2019-05-18 00:54:41 +05:30
def legacy_artifacts_file
return unless Feature.enabled?(:ci_enable_legacy_artifacts)
super
end
def legacy_artifacts_metadata
return unless Feature.enabled?(:ci_enable_legacy_artifacts)
super
end
2018-03-17 18:26:18 +05:30
end