2020-08-07 06:09:47 +00:00
# frozen_string_literal: true
2020-08-07 18:09:53 +00: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 06:09:47 +00:00
module Ci
class PipelineArtifact < ApplicationRecord
extend Gitlab :: Ci :: Model
2020-08-12 00:09:52 +00:00
include Artifactable
2020-08-19 21:10:32 +00:00
include FileStoreMounter
2020-08-07 06:09:47 +00:00
FILE_STORE_SUPPORTED = [
ObjectStorage :: Store :: LOCAL ,
ObjectStorage :: Store :: REMOTE
] . freeze
FILE_SIZE_LIMIT = 10 . megabytes . freeze
belongs_to :project , class_name : " Project " , inverse_of : :pipeline_artifacts
belongs_to :pipeline , class_name : " Ci::Pipeline " , inverse_of : :pipeline_artifacts
2020-08-12 12:10:25 +00:00
validates :pipeline , :project , :file_format , :file , presence : true
2020-08-07 06:09:47 +00:00
validates :file_store , presence : true , inclusion : { in : FILE_STORE_SUPPORTED }
validates :size , presence : true , numericality : { less_than_or_equal_to : FILE_SIZE_LIMIT }
2020-08-12 18:10:05 +00:00
validates :file_type , presence : true
2020-08-07 06:09:47 +00:00
2020-08-19 21:10:32 +00:00
mount_file_store_uploader Ci :: PipelineArtifactUploader
2020-08-13 15:10:03 +00:00
before_save :set_size , if : :file_changed?
2020-08-07 06:09:47 +00:00
enum file_type : {
code_coverage : 1
}
2020-08-13 15:10:03 +00:00
def set_size
self . size = file . size
end
2020-08-07 06:09:47 +00:00
end
end