40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module Gitlab
|
||
|
module Ci
|
||
|
module Reports
|
||
|
class CodequalityMrDiff
|
||
|
attr_reader :files
|
||
|
|
||
|
def initialize(raw_report)
|
||
|
@raw_report = raw_report
|
||
|
@files = {}
|
||
|
build_report!
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def build_report!
|
||
|
codequality_files = @raw_report.all_degradations.each_with_object({}) do |degradation, codequality_files|
|
||
|
unless codequality_files[degradation.dig(:location, :path)].present?
|
||
|
codequality_files[degradation.dig(:location, :path)] = []
|
||
|
end
|
||
|
|
||
|
build_mr_diff_payload(codequality_files, degradation)
|
||
|
end
|
||
|
|
||
|
@files = codequality_files
|
||
|
end
|
||
|
|
||
|
def build_mr_diff_payload(codequality_files, degradation)
|
||
|
codequality_files[degradation.dig(:location, :path)] << {
|
||
|
line: degradation.dig(:location, :lines, :begin) || degradation.dig(:location, :positions, :begin, :line),
|
||
|
description: degradation[:description],
|
||
|
severity: degradation[:severity]
|
||
|
}
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|