2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
# This class is being used to persist additional artifacts after a pipeline completes, which is a great place to cache a computed result in object storage
module Ci
class PipelineArtifact < ApplicationRecord
extend Gitlab :: Ci :: Model
2020-11-24 15:15:51 +05:30
include UpdateProjectStatistics
2020-10-24 23:57:45 +05:30
include Artifactable
include FileStoreMounter
2020-11-24 15:15:51 +05:30
include Presentable
2020-10-24 23:57:45 +05:30
FILE_SIZE_LIMIT = 10 . megabytes . freeze
2020-11-24 15:15:51 +05:30
EXPIRATION_DATE = 1 . week . freeze
DEFAULT_FILE_NAMES = {
code_coverage : 'code_coverage.json'
} . freeze
2020-10-24 23:57:45 +05:30
belongs_to :project , class_name : " Project " , inverse_of : :pipeline_artifacts
belongs_to :pipeline , class_name : " Ci::Pipeline " , inverse_of : :pipeline_artifacts
validates :pipeline , :project , :file_format , :file , presence : true
2020-11-24 15:15:51 +05:30
validates :file_store , presence : true , inclusion : { in : ObjectStorage :: SUPPORTED_STORES }
2020-10-24 23:57:45 +05:30
validates :size , presence : true , numericality : { less_than_or_equal_to : FILE_SIZE_LIMIT }
validates :file_type , presence : true
mount_file_store_uploader Ci :: PipelineArtifactUploader
2020-11-24 15:15:51 +05:30
update_project_statistics project_statistics_name : :pipeline_artifacts_size
2020-10-24 23:57:45 +05:30
enum file_type : {
code_coverage : 1
}
2020-11-24 15:15:51 +05:30
def self . has_code_coverage?
where ( file_type : :code_coverage ) . exists?
end
def self . find_with_code_coverage
find_by ( file_type : :code_coverage )
end
def present
super ( presenter_class : " Ci::PipelineArtifacts:: #{ self . file_type . camelize } Presenter " . constantize )
2020-10-24 23:57:45 +05:30
end
end
end