2020-08-07 02:09:47 -04:00
# frozen_string_literal: true
2020-08-07 14:09:53 -04:00
# 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
2020-08-07 02:09:47 -04:00
module Ci
class PipelineArtifact < ApplicationRecord
extend Gitlab :: Ci :: Model
2020-08-24 08:10:17 -04:00
include UpdateProjectStatistics
2020-08-11 20:09:52 -04:00
include Artifactable
2020-08-19 17:10:32 -04:00
include FileStoreMounter
2020-09-01 17:10:21 -04:00
include Presentable
2020-08-07 02:09:47 -04:00
FILE_SIZE_LIMIT = 10 . megabytes . freeze
2020-08-21 11:10:03 -04:00
EXPIRATION_DATE = 1 . week . freeze
DEFAULT_FILE_NAMES = {
code_coverage : 'code_coverage.json'
} . freeze
2020-08-07 02:09:47 -04:00
belongs_to :project , class_name : " Project " , inverse_of : :pipeline_artifacts
belongs_to :pipeline , class_name : " Ci::Pipeline " , inverse_of : :pipeline_artifacts
2020-08-12 08:10:25 -04:00
validates :pipeline , :project , :file_format , :file , presence : true
2020-09-17 17:09:39 -04:00
validates :file_store , presence : true , inclusion : { in : ObjectStorage :: SUPPORTED_STORES }
2020-08-07 02:09:47 -04:00
validates :size , presence : true , numericality : { less_than_or_equal_to : FILE_SIZE_LIMIT }
2020-08-12 14:10:05 -04:00
validates :file_type , presence : true
2020-08-07 02:09:47 -04:00
2020-08-19 17:10:32 -04:00
mount_file_store_uploader Ci :: PipelineArtifactUploader
2020-08-13 11:10:03 -04:00
2020-08-24 08:10:17 -04:00
update_project_statistics project_statistics_name : :pipeline_artifacts_size
2020-08-07 02:09:47 -04:00
enum file_type : {
code_coverage : 1
}
2020-08-13 11:10:03 -04:00
2020-08-21 11:10:03 -04:00
def self . has_code_coverage?
where ( file_type : :code_coverage ) . exists?
2020-08-13 11:10:03 -04:00
end
2020-08-25 08:04:30 -04:00
def self . find_with_code_coverage
find_by ( file_type : :code_coverage )
end
2020-09-01 17:10:21 -04:00
def present
super ( presenter_class : " Ci::PipelineArtifacts:: #{ self . file_type . camelize } Presenter " . constantize )
end
2020-08-07 02:09:47 -04:00
end
end