Class: Gitlab::Ci::Reports::CodequalityReports

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/reports/codequality_reports.rb

Constant Summary collapse

SEVERITY_PRIORITIES =

{ “blocker” => 0, “critical” => 1 … }

%w(blocker critical major minor info unknown).map.with_index.to_h.freeze
CODECLIMATE_SCHEMA_PATH =
Rails.root.join('app', 'validators', 'json_schemas', 'codeclimate.json').to_s

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCodequalityReports

Returns a new instance of CodequalityReports.


12
13
14
15
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 12

def initialize
  @degradations = {}.with_indifferent_access
  @error_message = nil
end

Instance Attribute Details

#degradationsObject (readonly)

Returns the value of attribute degradations.


7
8
9
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 7

def degradations
  @degradations
end

#error_messageObject (readonly)

Returns the value of attribute error_message.


7
8
9
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 7

def error_message
  @error_message
end

Instance Method Details

#add_degradation(degradation) ⇒ Object


17
18
19
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 17

def add_degradation(degradation)
  valid_degradation?(degradation) && @degradations[degradation.dig('fingerprint')] = degradation
end

#all_degradationsObject


29
30
31
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 29

def all_degradations
  @degradations.values
end

#degradations_countObject


25
26
27
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 25

def degradations_count
  @degradations.size
end

#set_error_message(error) ⇒ Object


21
22
23
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 21

def set_error_message(error)
  @error_message = error
end

#sort_degradations!Object


33
34
35
36
37
38
# File 'lib/gitlab/ci/reports/codequality_reports.rb', line 33

def sort_degradations!
  @degradations = @degradations.sort_by do |_fingerprint, degradation|
    severity = degradation.dig(:severity)&.downcase
    SEVERITY_PRIORITIES[severity] || SEVERITY_PRIORITIES['unknown']
  end.to_h
end