Commit dd9848c8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add add clair artifact methods to Build and Pipeline

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 77f5f723
......@@ -10,6 +10,7 @@ module EE
included do
scope :codequality, ->() { where(name: %w[codequality codeclimate]) }
scope :sast, ->() { where(name: 'sast') }
scope :clair, ->() { where(name: 'clair') }
after_save :stick_build_if_status_changed
end
......@@ -26,12 +27,21 @@ module EE
end
def has_codeclimate_json?
options.dig(:artifacts, :paths) == ['codeclimate.json'] &&
artifacts_metadata?
has_artifact?('codeclimate.json')
end
def has_sast_json?
options.dig(:artifacts, :paths) == ['gl-sast-report.json'] &&
has_artifact?('gl-sast-report.json')
end
def has_clair_json?
has_artifact?('gl-clair-report.json')
end
private
def has_artifact?(name)
options.dig(:artifacts, :paths) == [name] &&
artifacts_metadata?
end
end
......
......@@ -20,6 +20,10 @@ module EE
def sast_artifact
artifacts.sast.find(&:has_sast_json?)
end
def clair_artifact
artifacts.clair.find(&:has_clair_json?)
end
end
end
end
......@@ -128,71 +128,43 @@ describe Ci::Build do
end
end
describe '#has_codeclimate_json?' do
context 'valid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codequality',
pipeline: pipeline,
options: {
artifacts: {
paths: ['codeclimate.json']
ARTIFACTS_METHODS = {
has_codeclimate_json?: 'codeclimate.json',
has_sast_json?: 'gl-sast-report.json',
has_clair_json?: 'gl-clair-report.json'
}.freeze
ARTIFACTS_METHODS.each do |method, filename|
describe "##{method}" do
context 'valid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
pipeline: pipeline,
options: {
artifacts: {
paths: [filename]
}
}
}
)
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
)
end
describe '#has_sast_json?' do
context 'valid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'sast',
pipeline: pipeline,
options: {
artifacts: {
paths: ['gl-sast-report.json']
}
}
)
it { expect(build.send(method)).to be_truthy }
end
it { expect(build.has_sast_json?).to be_truthy }
end
context 'invalid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
pipeline: pipeline,
options: {}
)
end
context 'invalid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'sast',
pipeline: pipeline,
options: {}
)
it { expect(build.send(method)).to be_falsey }
end
it { expect(build.has_sast_json?).to be_falsey }
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