debian-mirror-gitlab/lib/gitlab/ci/parsers/codequality/code_climate.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.3 KiB
Ruby
Raw Normal View History

2021-02-22 17:27:13 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
module Parsers
module Codequality
class CodeClimate
2023-01-13 00:05:48 +05:30
def parse!(json_data, codequality_report, metadata = {})
2021-02-22 17:27:13 +05:30
root = Gitlab::Json.parse(json_data)
2023-01-13 00:05:48 +05:30
parse_all(root, codequality_report, metadata)
2021-02-22 17:27:13 +05:30
rescue JSON::ParserError => e
codequality_report.set_error_message("JSON parsing failed: #{e}")
end
private
2023-01-13 00:05:48 +05:30
def parse_all(root, codequality_report, metadata)
2021-02-22 17:27:13 +05:30
return unless root.present?
root.each do |degradation|
2023-01-13 00:05:48 +05:30
break unless codequality_report.valid_degradation?(degradation)
degradation['web_url'] = web_url(degradation, metadata)
codequality_report.add_degradation(degradation)
2021-02-22 17:27:13 +05:30
end
end
2023-01-13 00:05:48 +05:30
def web_url(degradation, metadata)
return unless metadata[:project].present? && metadata[:commit_sha].present?
path = degradation.dig('location', 'path')
line = degradation.dig('location', 'lines', 'begin') ||
degradation.dig('location', 'positions', 'begin', 'line')
"#{Routing.url_helpers.project_blob_url(
metadata[:project], File.join(metadata[:commit_sha], path))}#L#{line}"
end
2021-02-22 17:27:13 +05:30
end
end
end
end
end