debian-mirror-gitlab/lib/gitlab/ci/parsers/accessibility/pa11y.rb

34 lines
877 B
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
module Parsers
module Accessibility
class Pa11y
def parse!(json_data, accessibility_report)
root = Gitlab::Json.parse(json_data).with_indifferent_access
parse_all(root, accessibility_report)
rescue JSON::ParserError => e
accessibility_report.set_error_message("JSON parsing failed: #{e}")
rescue StandardError => e
accessibility_report.set_error_message("Pa11y parsing failed: #{e}")
end
private
def parse_all(root, accessibility_report)
return unless root.present?
root.dig("results").each do |url, value|
accessibility_report.add_url(url, value)
end
accessibility_report
end
end
end
end
end
end