Commit 5261047c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor codeclimate related code for build and pipeline

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 87d1a814
...@@ -441,6 +441,11 @@ module Ci ...@@ -441,6 +441,11 @@ module Ci
trace trace
end end
def has_codeclimate_json?
options.dig(:artifacts, :paths) == ['codeclimate.json'] &&
artifacts_metadata?
end
private private
def update_artifacts_size def update_artifacts_size
......
...@@ -397,10 +397,7 @@ module Ci ...@@ -397,10 +397,7 @@ module Ci
end end
def codeclimate_artifact def codeclimate_artifact
artifacts.codeclimate.find do |artifact| artifacts.codeclimate.find(&:has_codeclimate_json?)
artifact.options[:artifacts][:paths] == ['codeclimate.json'] &&
artifact.artifacts_metadata?
end
end end
private private
......
...@@ -1367,4 +1367,38 @@ describe Ci::Build, :models do ...@@ -1367,4 +1367,38 @@ describe Ci::Build, :models do
build.enqueue build.enqueue
end end
end end
describe '#has_codeclimate_json?' do
context 'valid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codeclimate',
pipeline: pipeline,
options: {
artifacts: {
paths: ['codeclimate.json']
}
}
)
end
it { expect(build.has_codeclimate_json?).to be_truthy }
end
context 'invalid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codeclimate',
pipeline: pipeline,
options: {}
)
end
it { expect(build.has_codeclimate_json?).to be_falsey }
end
end
end end
...@@ -1220,6 +1220,7 @@ describe Ci::Pipeline, models: true do ...@@ -1220,6 +1220,7 @@ describe Ci::Pipeline, models: true do
end end
describe '#codeclimate_artifact' do describe '#codeclimate_artifact' do
context 'has codeclimate build' do
let!(:build) do let!(:build) do
create( create(
:ci_build, :ci_build,
...@@ -1234,8 +1235,13 @@ describe Ci::Pipeline, models: true do ...@@ -1234,8 +1235,13 @@ describe Ci::Pipeline, models: true do
) )
end end
it do it { expect(pipeline.codeclimate_artifact).to eq(build) }
expect(pipeline.codeclimate_artifact).to eq(build) end
context 'no codeclimate build' do
before { create(:ci_build, pipeline: pipeline) }
it { expect(pipeline.codeclimate_artifact).to be_nil }
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