This repository has been archived on 2023-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
coverage-check-action/lib/coverage_report.rb
2020-03-17 01:19:42 +01:00

34 lines
894 B
Ruby

# frozen_string_literal: true
class CoverageReport
class << self
def generate(type, report_path, data)
if type == 'simplecov'
simplecov(report_path, data)
elsif type == 'lcov'
lcov(report_path, data)
else
raise 'InvalidCoverageReportType'
end
end
def simplecov(report_path, data)
report = read_json(report_path)
minumum_percent = data[:min]
covered_percent = report.dig('result', 'covered_percent')
{ 'lines' => { 'covered_percent' => covered_percent, 'minumum_percent' => minumum_percent } }
end
def lcov(report_path, data)
lcov = LcovParse.new(File.read("/github/workspace/#{report_path}"))
{ 'lines' => { 'covered_percent' => lcov.covered_percent, 'minumum_percent' => data[:min] } }
end
private
def read_json(path)
JSON.parse(File.read(path))
end
end
end