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-24 12:10:17 +00:00
include UpdateProjectStatistics
2020-08-12 00:09:52 +00:00
include Artifactable
2020-08-19 21:10:32 +00:00
include FileStoreMounter
2020-09-01 21:10:21 +00:00
include Presentable
2020-08-07 06:09:47 +00:00
FILE_SIZE_LIMIT = 10 . megabytes . freeze
2020-08-21 15:10:03 +00:00
EXPIRATION_DATE = 1 . week . freeze
DEFAULT_FILE_NAMES = {
2021-01-22 18:09:10 +00:00
code_coverage : 'code_coverage.json' ,
2021-02-03 18:09:25 +00:00
code_quality_mr_diff : 'code_quality_mr_diff.json'
2020-08-21 15:10:03 +00:00
} . freeze
2020-08-07 06:09:47 +00: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 12:10:25 +00:00
validates :pipeline , :project , :file_format , :file , presence : true
2020-09-17 21:09:39 +00:00
validates :file_store , presence : true , inclusion : { in : ObjectStorage :: SUPPORTED_STORES }
2020-08-07 06:09:47 +00:00
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
2020-08-24 12:10:17 +00:00
update_project_statistics project_statistics_name : :pipeline_artifacts_size
2020-08-07 06:09:47 +00:00
enum file_type : {
2021-01-19 21:10:45 +00:00
code_coverage : 1 ,
2021-02-03 18:09:25 +00:00
code_quality_mr_diff : 2
2020-08-07 06:09:47 +00:00
}
2020-08-13 15:10:03 +00:00
2021-01-19 21:10:45 +00:00
class << self
def has_report? ( file_type )
where ( file_type : file_type ) . exists?
end
2020-08-25 12:04:30 +00:00
2021-01-19 21:10:45 +00:00
def find_by_file_type ( file_type )
find_by ( file_type : file_type )
end
2020-08-25 12:04:30 +00:00
end
2020-09-01 21:10:21 +00:00
def present
super ( presenter_class : " Ci::PipelineArtifacts:: #{ self . file_type . camelize } Presenter " . constantize )
end
2020-08-07 06:09:47 +00:00
end
end