Class: Ci::PipelineArtifact

Inherits:
ApplicationRecord show all
Includes:
Artifactable, Lockable, Partitionable, FileStoreMounter, Presentable, UpdateProjectStatistics
Defined in:
app/models/ci/pipeline_artifact.rb

Constant Summary collapse

FILE_SIZE_LIMIT =
10.megabytes.freeze
EXPIRATION_DATE =
1.week.freeze
DEFAULT_FILE_NAMES =
{
  code_coverage: 'code_coverage.json',
  code_quality_mr_diff: 'code_quality_mr_diff.json'
}.freeze
REPORT_TYPES =
{
  code_coverage: :raw,
  code_quality_mr_diff: :raw
}.freeze

Constants included from FileStoreMounter

FileStoreMounter::ALLOWED_FILE_FIELDS

Constants included from Artifactable

Artifactable::FILE_FORMAT_ADAPTERS, Artifactable::JUNIT_MAX_BYTES, Artifactable::NotSupportedAdapterError, Artifactable::STORE_COLUMN

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Artifactable

#each_blob

Methods included from Gitlab::Ci::Artifacts::Logger

#log_artifacts_context, #log_artifacts_filesize, #log_build_dependencies, log_created, log_deleted

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods included from Partitionable

registered_models

Methods inherited from ApplicationRecord

model_name, table_name_prefix

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.create_or_replace_for_pipeline!(pipeline:, file_type:, file:, size:, locked: :unknown) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/ci/pipeline_artifact.rb', line 59

def create_or_replace_for_pipeline!(pipeline:, file_type:, file:, size:, locked: :unknown)
  transaction do
    pipeline.pipeline_artifacts.find_by_file_type(file_type)&.destroy!

    pipeline.pipeline_artifacts.create!(
      file_type: file_type,
      project_id: pipeline.project_id,
      size: size,
      file: file,
      file_format: REPORT_TYPES[file_type],
      expire_at: EXPIRATION_DATE.from_now,
      locked: locked
    )
  end
rescue ActiveRecord::ActiveRecordError => err
  Gitlab::ErrorTracking.track_and_raise_exception(err, { pipeline_id: pipeline.id, file_type: file_type })
end

.find_by_file_type(file_type) ⇒ Object



55
56
57
# File 'app/models/ci/pipeline_artifact.rb', line 55

def find_by_file_type(file_type)
  find_by(file_type: file_type)
end

.report_exists?(file_type) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'app/models/ci/pipeline_artifact.rb', line 49

def report_exists?(file_type)
  return false unless REPORT_TYPES.key?(file_type)

  where(file_type: file_type).exists?
end

Instance Method Details

#presentObject



78
79
80
# File 'app/models/ci/pipeline_artifact.rb', line 78

def present
  super(presenter_class: "Ci::PipelineArtifacts::#{self.file_type.camelize}Presenter".constantize)
end