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 = {
2021-01-22 13:09:10 -05:00
code_coverage : 'code_coverage.json' ,
2021-02-03 13:09:25 -05:00
code_quality_mr_diff : 'code_quality_mr_diff.json'
2020-08-21 11:10:03 -04:00
} . freeze
2020-08-07 02:09:47 -04:00
2021-02-05 07:09:31 -05:00
REPORT_TYPES = {
code_coverage : :raw ,
code_quality_mr_diff : :raw
} . 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 : {
2021-01-19 16:10:45 -05:00
code_coverage : 1 ,
2021-02-03 13:09:25 -05:00
code_quality_mr_diff : 2
2020-08-07 02:09:47 -04:00
}
2020-08-13 11:10:03 -04:00
2021-01-19 16:10:45 -05:00
class << self
2021-02-05 07:09:31 -05:00
def report_exists? ( file_type )
return false unless REPORT_TYPES . key? ( file_type )
2021-01-19 16:10:45 -05:00
where ( file_type : file_type ) . exists?
end
2020-08-25 08:04:30 -04:00
2021-01-19 16:10:45 -05:00
def find_by_file_type ( file_type )
find_by ( file_type : file_type )
end
2020-08-25 08:04:30 -04:00
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