Commit a6a354d8 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'mo-refactor-pipeline-artifact-2' into 'master'

Introduce report type in pipeline artifact

See merge request gitlab-org/gitlab!53273
parents 0886a509 08c859fe
......@@ -996,7 +996,7 @@ module Ci
end
def has_coverage_reports?
pipeline_artifacts&.has_report?(:code_coverage)
pipeline_artifacts&.report_exists?(:code_coverage)
end
def can_generate_coverage_reports?
......@@ -1004,7 +1004,7 @@ module Ci
end
def has_codequality_mr_diff_report?
pipeline_artifacts&.has_report?(:code_quality_mr_diff)
pipeline_artifacts&.report_exists?(:code_quality_mr_diff)
end
def can_generate_codequality_reports?
......
......@@ -18,6 +18,11 @@ module Ci
code_quality_mr_diff: 'code_quality_mr_diff.json'
}.freeze
REPORT_TYPES = {
code_coverage: :raw,
code_quality_mr_diff: :raw
}.freeze
belongs_to :project, class_name: "Project", inverse_of: :pipeline_artifacts
belongs_to :pipeline, class_name: "Ci::Pipeline", inverse_of: :pipeline_artifacts
......@@ -36,7 +41,9 @@ module Ci
}
class << self
def has_report?(file_type)
def report_exists?(file_type)
return false unless REPORT_TYPES.key?(file_type)
where(file_type: file_type).exists?
end
......
......@@ -11,7 +11,7 @@ module Ci
pipeline.pipeline_artifacts.create!(
project_id: pipeline.project_id,
file_type: :code_coverage,
file_format: :raw,
file_format: Ci::PipelineArtifact::REPORT_TYPES.fetch(:code_coverage),
size: file["tempfile"].size,
file: file,
expire_at: Ci::PipelineArtifact::EXPIRATION_DATE.from_now
......
......@@ -11,7 +11,7 @@ module Ci
pipeline.pipeline_artifacts.create!(
project_id: pipeline.project_id,
file_type: :code_quality_mr_diff,
file_format: :raw,
file_format: Ci::PipelineArtifact::REPORT_TYPES.fetch(:code_quality_mr_diff),
size: file["tempfile"].size,
file: file,
expire_at: Ci::PipelineArtifact::EXPIRATION_DATE.from_now
......
......@@ -76,8 +76,8 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
end
end
describe '.has_report?' do
subject(:pipeline_artifact) { Ci::PipelineArtifact.has_report?(file_type) }
describe '.report_exists?' do
subject(:pipeline_artifact) { Ci::PipelineArtifact.report_exists?(file_type) }
context 'when file_type is code_coverage' do
let(:file_type) { :code_coverage }
......@@ -173,11 +173,21 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
end
describe '#present' do
subject { coverage_report.present }
subject(:presenter) { report.present }
context 'when file_type is code_coverage' do
let(:report) { coverage_report }
it 'uses code coverage presenter' do
expect(subject.present).to be_kind_of(Ci::PipelineArtifacts::CodeCoveragePresenter)
expect(presenter).to be_kind_of(Ci::PipelineArtifacts::CodeCoveragePresenter)
end
end
context 'when file_type is code_quality_mr_diff' do
let(:report) { create(:ci_pipeline_artifact, :with_codequality_mr_diff_report) }
it 'uses code codequality mr diff presenter' do
expect(presenter).to be_kind_of(Ci::PipelineArtifacts::CodeQualityMrDiffPresenter)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment