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