Commit 771cfb14 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add clair to merge request model and serializer

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent dd9848c8
...@@ -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'
SAST_FILE = 'gl-sast-report.json'
CLAIR_FILE = 'gl-clair-report.json'
included do included do
scope :codequality, ->() { where(name: %w[codequality codeclimate]) } scope :codequality, ->() { where(name: %w[codequality codeclimate]) }
scope :sast, ->() { where(name: 'sast') } scope :sast, ->() { where(name: 'sast') }
...@@ -27,15 +31,15 @@ module EE ...@@ -27,15 +31,15 @@ module EE
end end
def has_codeclimate_json? def has_codeclimate_json?
has_artifact?('codeclimate.json') has_artifact?(CODEQUALITY_FILE)
end end
def has_sast_json? def has_sast_json?
has_artifact?('gl-sast-report.json') has_artifact?(SAST_FILE)
end end
def has_clair_json? def has_clair_json?
has_artifact?('gl-clair-report.json') has_artifact?(CLAIR_FILE)
end end
private private
......
...@@ -12,6 +12,7 @@ module EE ...@@ -12,6 +12,7 @@ module EE
delegate :codeclimate_artifact, to: :head_pipeline, prefix: :head, allow_nil: true delegate :codeclimate_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
delegate :codeclimate_artifact, to: :base_pipeline, prefix: :base, allow_nil: true delegate :codeclimate_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
delegate :sast_artifact, to: :head_pipeline, allow_nil: true delegate :sast_artifact, to: :head_pipeline, allow_nil: true
delegate :clair_artifact, to: :head_pipeline, allow_nil: true
delegate :sha, to: :head_pipeline, prefix: :head_pipeline, allow_nil: true delegate :sha, to: :head_pipeline, prefix: :head_pipeline, allow_nil: true
delegate :sha, to: :base_pipeline, prefix: :base_pipeline, allow_nil: true delegate :sha, to: :base_pipeline, prefix: :base_pipeline, allow_nil: true
end end
...@@ -47,5 +48,9 @@ module EE ...@@ -47,5 +48,9 @@ module EE
def has_sast_data? def has_sast_data?
sast_artifact&.success? sast_artifact&.success?
end end
def has_clair_data?
clair_artifact&.success?
end
end end
end end
...@@ -55,6 +55,7 @@ class License < ActiveRecord::Base ...@@ -55,6 +55,7 @@ class License < ActiveRecord::Base
EEU_FEATURES = EEP_FEATURES + %i[ EEU_FEATURES = EEP_FEATURES + %i[
sast sast
epics epics
clair
].freeze ].freeze
# List all features available for early adopters, # List all features available for early adopters,
......
...@@ -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,7 +29,19 @@ module EE ...@@ -29,7 +29,19 @@ 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
expose :blob_path, if: -> (mr, _) { mr.head_pipeline_sha } do |merge_request|
project_blob_path(merge_request.project, merge_request.head_pipeline_sha)
end
end
expose :clair, if: -> (mr, _) { expose_clair_data?(mr, current_user) } do
expose :path do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.clair_artifact,
path: Ci::Build::CLAIR_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|
...@@ -45,5 +57,11 @@ module EE ...@@ -45,5 +57,11 @@ module EE
mr.has_sast_data? && mr.has_sast_data? &&
can?(current_user, :read_build, mr.sast_artifact) can?(current_user, :read_build, mr.sast_artifact)
end end
def expose_clair_data?(mr, current_user)
mr.project.feature_available?(:clair) &&
mr.has_clair_data? &&
can?(current_user, :read_build, mr.clair_artifact)
end
end end
end end
...@@ -4,7 +4,6 @@ describe MergeRequestEntity do ...@@ -4,7 +4,6 @@ describe MergeRequestEntity do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create :project, :repository } let(:project) { create :project, :repository }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let(:build) { create(:ci_build, name: 'sast') }
let(:request) { double('request', current_user: user) } let(:request) { double('request', current_user: user) }
subject do subject do
...@@ -12,9 +11,20 @@ describe MergeRequestEntity do ...@@ -12,9 +11,20 @@ describe MergeRequestEntity do
end end
it 'has sast data' do it 'has sast data' do
build = create(:ci_build, name: 'sast')
allow(subject).to receive(:expose_sast_data?).and_return(true) allow(subject).to receive(:expose_sast_data?).and_return(true)
allow(merge_request).to receive(:sast_artifact).and_return(build) allow(merge_request).to receive(:sast_artifact).and_return(build)
expect(subject.as_json).to include(:sast) expect(subject.as_json).to include(:sast)
end end
it 'has clair data' do
build = create(:ci_build, name: 'clair')
allow(subject).to receive(:expose_clair_data?).and_return(true)
allow(merge_request).to receive(:clair_artifact).and_return(build)
expect(subject.as_json).to include(:clair)
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