Commit 456ef34e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move codequalit and sast code from merge_request_entity.rb to ee module

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent d0da57ce
class MergeRequestEntity < IssuableEntity class MergeRequestEntity < IssuableEntity
include TimeTrackableEntity include TimeTrackableEntity
prepend ::EE::MergeRequestEntity
expose :state expose :state
expose :deleted_at expose :deleted_at
...@@ -189,41 +190,6 @@ class MergeRequestEntity < IssuableEntity ...@@ -189,41 +190,6 @@ class MergeRequestEntity < IssuableEntity
commit_change_content_project_merge_request_path(merge_request.project, merge_request) commit_change_content_project_merge_request_path(merge_request.project, merge_request)
end end
# EE-specific
expose :codeclimate, if: -> (mr, _) { mr.has_codeclimate_data? } do
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')
end
expose :head_blob_path, if: -> (mr, _) { mr.head_pipeline_sha } do |merge_request|
project_blob_path(merge_request.project, merge_request.head_pipeline_sha)
end
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')
end
expose :base_blob_path, if: -> (mr, _) { mr.base_pipeline_sha } do |merge_request|
project_blob_path(merge_request.project, merge_request.base_pipeline_sha)
end
end
expose :sast, if: -> (mr, _) { expose_sast_data?(mr, current_user) } do
expose :path do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.sast_artifact,
path: 'gl-sast-report.json')
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
private private
delegate :current_user, to: :request delegate :current_user, to: :request
...@@ -232,10 +198,4 @@ class MergeRequestEntity < IssuableEntity ...@@ -232,10 +198,4 @@ class MergeRequestEntity < IssuableEntity
@presenters ||= {} @presenters ||= {}
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) @presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user)
end end
def expose_sast_data?(mr, current_user)
mr.project.feature_available?(:sast) &&
mr.has_sast_data? &&
can?(current_user, :read_build, mr.sast_artifact)
end
end end
module EE
module MergeRequestEntity
extend ActiveSupport::Concern
prepended do
expose :codeclimate, if: -> (mr, _) { mr.has_codeclimate_data? } do
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')
end
expose :head_blob_path, if: -> (mr, _) { mr.head_pipeline_sha } do |merge_request|
project_blob_path(merge_request.project, merge_request.head_pipeline_sha)
end
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')
end
expose :base_blob_path, if: -> (mr, _) { mr.base_pipeline_sha } do |merge_request|
project_blob_path(merge_request.project, merge_request.base_pipeline_sha)
end
end
expose :sast, if: -> (mr, _) { expose_sast_data?(mr, current_user) } do
expose :path do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.sast_artifact,
path: 'gl-sast-report.json')
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
end
private
def expose_sast_data?(mr, current_user)
mr.project.feature_available?(:sast) &&
mr.has_sast_data? &&
can?(current_user, :read_build, mr.sast_artifact)
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