adapter for coverage
This commit is contained in:
parent
f745a541cc
commit
d7c0892c88
@ -1,13 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class GithubCheckRunService
|
||||
CHECK_NAME = 'Brakeman'
|
||||
CHECK_NAME = 'Coverage'
|
||||
|
||||
def initialize(report, github_data, report_adapter)
|
||||
@report = report
|
||||
@github_data = github_data
|
||||
@report_adapter = report_adapter
|
||||
@client = GithubClient.new(@github_data[:token], user_agent: 'brakeman-action')
|
||||
@client = GithubClient.new(@github_data[:token], user_agent: 'coverage-action')
|
||||
end
|
||||
|
||||
def run
|
||||
|
||||
@ -7,40 +7,15 @@ class ReportAdapter
|
||||
ANNOTATION_LEVEL = { notice: 'notice', warning: 'warning', failure: 'failure' }.freeze
|
||||
|
||||
def conslusion(report)
|
||||
return CONCLUSION_TYPES[:failure] if security_warnings(report).positive?
|
||||
|
||||
CONCLUSION_TYPES[:success]
|
||||
end
|
||||
|
||||
def summary(report)
|
||||
"**Brakeman Report**:\n#{security_warnings(report)} security warnings\n#{check_table(report)}"
|
||||
"**Coverage**: #{report.dig('result', 'covered_percent')}%"
|
||||
end
|
||||
|
||||
def annotations(report)
|
||||
report['warnings'].map do |error|
|
||||
{
|
||||
'path' => error['file'],
|
||||
'start_line' => error['line'],
|
||||
'end_line' => error['line'],
|
||||
'annotation_level' => ANNOTATION_LEVEL[:warning],
|
||||
'title' => "#{error['confidence']} - #{error['check_name']}",
|
||||
'message' => error['message']
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_table(report)
|
||||
uniq_checks(report).reduce('') { |memo, check| memo + "- [#{check[:check_name]}](#{check[:link]})\n" }
|
||||
end
|
||||
|
||||
def uniq_checks(report)
|
||||
report['warnings'].map { |w| { check_name: w['check_name'], link: w['link'] } }.uniq { |w| w[:check_name] }
|
||||
end
|
||||
|
||||
def security_warnings(report)
|
||||
report['scan_info']['security_warnings']
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user