diff options
Diffstat (limited to 'app/models/ci/job_artifact.rb')
-rw-r--r-- | app/models/ci/job_artifact.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb index 6fc2d9e8282..a736e2b0e22 100644 --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -10,6 +10,7 @@ module Ci mount_uploader :file, JobArtifactUploader validates :file_format, presence: true, unless: :ignore_schema, on: :create + validate :valid_file_format?, unless: :ignore_schema, on: :create before_save :set_size, if: :file_changed? after_save :update_project_statistics_after_save, if: :size_changed? after_destroy :update_project_statistics_after_destroy, unless: :project_destroyed? @@ -36,6 +37,7 @@ module Ci GENERAL_ARCHIVE_FILE_TYPE = 'archive'.freeze TEST_REPORT_FILE_TYPES = %w[junit].freeze DEFAULT_FILE_NAMES = { junit: 'junit.xml' }.freeze + TYPE_AND_FORMAT_PAIRS = { archive: :zip, metadata: :gzip, trace: :raw, junit: :gzip }.freeze enum file_format: { raw: 1, @@ -43,6 +45,12 @@ module Ci gzip: 3 } + def valid_file_format? + unless TYPE_AND_FORMAT_PAIRS[self.file_type&.to_sym] == self.file_format&.to_sym + errors.add(:file_format, 'Invalid file format with specified file type') + end + end + def ignore_schema ActiveRecord::Migrator.current_version <= ::Gitlab::Ci::Trace::ARCHIVE_LEGACY_TRACES_MIGRATION_VERSION end |