Commit 834ae7bc authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'dz-refactor-specific-build-artifacts' into 'master'

Refactor specific build artifacts code

See merge request gitlab-org/gitlab-ee!3689
parents f7cf3c25 8b386ec0
...@@ -7,6 +7,10 @@ module EE ...@@ -7,6 +7,10 @@ module EE
module Build module Build
extend ActiveSupport::Concern extend ActiveSupport::Concern
CODEQUALITY_FILE = 'codeclimate.json'.freeze
SAST_FILE = 'gl-sast-report.json'.freeze
PERFORMANCE_FILE = 'performance.json'.freeze
included do included do
scope :codequality, ->() { where(name: %w[codequality codeclimate]) } scope :codequality, ->() { where(name: %w[codequality codeclimate]) }
scope :performance, ->() { where(name: %w[performance deploy]) } scope :performance, ->() { where(name: %w[performance deploy]) }
...@@ -27,17 +31,21 @@ module EE ...@@ -27,17 +31,21 @@ module EE
end end
def has_codeclimate_json? def has_codeclimate_json?
options.dig(:artifacts, :paths) == ['codeclimate.json'] && has_artifact?(CODEQUALITY_FILE)
artifacts_metadata?
end end
def has_performance_json? def has_performance_json?
options.dig(:artifacts, :paths) == ['performance.json'] && has_artifact?(PERFORMANCE_FILE)
artifacts_metadata?
end end
def has_sast_json? def has_sast_json?
options.dig(:artifacts, :paths) == ['gl-sast-report.json'] && has_artifact?(SAST_FILE)
end
private
def has_artifact?(name)
options.dig(:artifacts, :paths) == [name] &&
artifacts_metadata? artifacts_metadata?
end end
end end
......
...@@ -7,7 +7,7 @@ module EE ...@@ -7,7 +7,7 @@ module EE
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_codeclimate_artifact) } do |merge_request| expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_codeclimate_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project, raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_codeclimate_artifact, merge_request.head_codeclimate_artifact,
path: 'codeclimate.json') path: Ci::Build::CODEQUALITY_FILE)
end end
expose :head_blob_path, if: -> (mr, _) { mr.head_pipeline_sha } do |merge_request| expose :head_blob_path, if: -> (mr, _) { mr.head_pipeline_sha } do |merge_request|
...@@ -17,7 +17,7 @@ module EE ...@@ -17,7 +17,7 @@ module EE
expose :base_path, if: -> (mr, _) { can?(current_user, :read_build, mr.base_codeclimate_artifact) } do |merge_request| expose :base_path, if: -> (mr, _) { can?(current_user, :read_build, mr.base_codeclimate_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project, raw_project_build_artifacts_url(merge_request.target_project,
merge_request.base_codeclimate_artifact, merge_request.base_codeclimate_artifact,
path: 'codeclimate.json') path: Ci::Build::CODEQUALITY_FILE)
end end
expose :base_blob_path, if: -> (mr, _) { mr.base_pipeline_sha } do |merge_request| expose :base_blob_path, if: -> (mr, _) { mr.base_pipeline_sha } do |merge_request|
...@@ -29,13 +29,13 @@ module EE ...@@ -29,13 +29,13 @@ module EE
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_performance_artifact) } do |merge_request| expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_performance_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project, raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_performance_artifact, merge_request.head_performance_artifact,
path: 'performance.json') path: Ci::Build::PERFORMANCE_FILE)
end end
expose :base_path, if: -> (mr, _) { can?(current_user, :read_build, mr.base_performance_artifact) } do |merge_request| expose :base_path, if: -> (mr, _) { can?(current_user, :read_build, mr.base_performance_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project, raw_project_build_artifacts_url(merge_request.target_project,
merge_request.base_performance_artifact, merge_request.base_performance_artifact,
path: 'performance.json') path: Ci::Build::PERFORMANCE_FILE)
end end
end end
...@@ -43,7 +43,7 @@ module EE ...@@ -43,7 +43,7 @@ module EE
expose :path do |merge_request| expose :path do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project, raw_project_build_artifacts_url(merge_request.source_project,
merge_request.sast_artifact, merge_request.sast_artifact,
path: 'gl-sast-report.json') path: Ci::Build::SAST_FILE)
end end
expose :blob_path, if: -> (mr, _) { mr.head_pipeline_sha } do |merge_request| expose :blob_path, if: -> (mr, _) { mr.head_pipeline_sha } do |merge_request|
......
...@@ -128,105 +128,43 @@ describe Ci::Build do ...@@ -128,105 +128,43 @@ describe Ci::Build do
end end
end end
describe '#has_codeclimate_json?' do ARTIFACTS_METHODS = {
context 'valid build' do has_codeclimate_json?: Ci::Build::CODEQUALITY_FILE,
let!(:build) do has_performance_json?: Ci::Build::PERFORMANCE_FILE,
create( has_sast_json?: Ci::Build::SAST_FILE
:ci_build, }.freeze
:artifacts,
name: 'codequality', ARTIFACTS_METHODS.each do |method, filename|
pipeline: pipeline, describe "##{method}" do
options: { context 'valid build' do
artifacts: { let!(:build) do
paths: ['codeclimate.json'] create(
:ci_build,
:artifacts,
pipeline: pipeline,
options: {
artifacts: {
paths: [filename]
}
} }
} )
) end
end
it { expect(build.has_codeclimate_json?).to be_truthy }
end
context 'invalid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codequality',
pipeline: pipeline,
options: {}
)
end
it { expect(build.has_codeclimate_json?).to be_falsey }
end
end
describe '#has_performance_json?' do
context 'valid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'performance',
pipeline: pipeline,
options: {
artifacts: {
paths: ['performance.json']
}
}
)
end
it { expect(build.has_performance_json?).to be_truthy }
end
context 'invalid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'performance',
pipeline: pipeline,
options: {}
)
end
it { expect(build.has_performance_json?).to be_falsey }
end
end
describe '#has_sast_json?' do it { expect(build.send(method)).to be_truthy }
context 'valid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'sast',
pipeline: pipeline,
options: {
artifacts: {
paths: ['gl-sast-report.json']
}
}
)
end end
it { expect(build.has_sast_json?).to be_truthy } context 'invalid build' do
end let!(:build) do
create(
:ci_build,
:artifacts,
pipeline: pipeline,
options: {}
)
end
context 'invalid build' do it { expect(build.send(method)).to be_falsey }
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'sast',
pipeline: pipeline,
options: {}
)
end end
it { expect(build.has_sast_json?).to be_falsey }
end end
end 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