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/report_adapter.rb
Abimael Martell b8506db951
Add percentage on result title (#4)
* Add percentage to action name

* Test with percentage in output title
2020-10-04 19:10:13 +02:00

36 lines
1.0 KiB
Ruby

# frozen_string_literal: true
# https://developer.github.com/v3/checks/runs/#output-object
class ReportAdapter
class << self
CONCLUSION_TYPES = { failure: 'failure', success: 'success' }.freeze
ANNOTATION_LEVEL = { notice: 'notice', warning: 'warning', failure: 'failure' }.freeze
def conslusion(report)
lines_covered_percent(report) >= lines_minimum_percent(report).to_f ? CONCLUSION_TYPES[:success] : CONCLUSION_TYPES[:failure]
end
def summary(report)
"**Coverage**:\n\n#{table_head}\n| Lines | #{lines_covered_percent(report)}% | #{lines_minimum_percent(report)}% |\n"
end
def annotations(_report)
[]
end
def lines_covered_percent(report)
@lines_covered_percent ||= report.dig('lines', 'covered_percent')
end
private
def table_head
"| Type | covered | minimum |\n| ----- | ------- | ------- |"
end
def lines_minimum_percent(report)
@lines_minimum_percent ||= report.dig('lines', 'minumum_percent')
end
end
end