Commit 2dcbe3d2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor code climate artifact code on backend

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent a04a9c38
...@@ -34,6 +34,9 @@ class MergeRequest < ActiveRecord::Base ...@@ -34,6 +34,9 @@ class MergeRequest < ActiveRecord::Base
delegate :commits, :real_size, :commits_sha, :commits_count, delegate :commits, :real_size, :commits_sha, :commits_count,
to: :merge_request_diff, prefix: nil to: :merge_request_diff, prefix: nil
delegate :codeclimate_artifact, to: :head_pipeline, prefix: :head, allow_nil: true
delegate :codeclimate_artifact, to: :base_pipeline, prefix: :base, allow_nil: true
# When this attribute is true some MR validation is ignored # When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests # It allows us to close or modify broken merge requests
attr_accessor :allow_broken attr_accessor :allow_broken
...@@ -996,16 +999,8 @@ class MergeRequest < ActiveRecord::Base ...@@ -996,16 +999,8 @@ class MergeRequest < ActiveRecord::Base
@base_pipeline ||= project.pipelines.find_by(sha: merge_request_diff&.base_commit_sha) @base_pipeline ||= project.pipelines.find_by(sha: merge_request_diff&.base_commit_sha)
end end
def codeclimate_artifact
@codeclimate_artifact ||= head_pipeline&.codeclimate_artifact
end
def base_codeclimate_artifact
@base_codeclimate_artifact ||= base_pipeline&.codeclimate_artifact
end
def has_codeclimate_data? def has_codeclimate_data?
codeclimate_artifact&.success? && head_codeclimate_artifact&.success? &&
base_codeclimate_artifact&.success? base_codeclimate_artifact&.success?
end end
end end
...@@ -197,17 +197,17 @@ class MergeRequestEntity < IssuableEntity ...@@ -197,17 +197,17 @@ class MergeRequestEntity < IssuableEntity
end end
# EE-specific # EE-specific
expose :codeclimate, if: lambda { |mr, _| mr.has_codeclimate_data? && can?(current_user, :read_build, mr.project) } do expose :codeclimate, if: -> (mr, _) { mr.has_codeclimate_data? } do
expose :head_path do |merge_request| expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_codeclimate_artifact) } do |merge_request|
raw_namespace_project_build_artifacts_url(merge_request.project.namespace, raw_namespace_project_build_artifacts_url(merge_request.source_project.namespace,
merge_request.project, merge_request.source_project,
merge_request.codeclimate_artifact, merge_request.head_codeclimate_artifact,
path: 'codeclimate.json') path: 'codeclimate.json')
end end
expose :base_path do |merge_request| expose :base_path, if: -> (mr, _) { can?(current_user, :read_build, mr.base_codeclimate_artifact) } do |merge_request|
raw_namespace_project_build_artifacts_url(merge_request.project.namespace, raw_namespace_project_build_artifacts_url(merge_request.target_project.namespace,
merge_request.project, merge_request.target_project,
merge_request.base_codeclimate_artifact, merge_request.base_codeclimate_artifact,
path: 'codeclimate.json') path: 'codeclimate.json')
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