generate coverage report
This commit is contained in:
parent
9247c263a3
commit
e86bde2331
27
lib/coverage_report.rb
Normal file
27
lib/coverage_report.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CoverageReport
|
||||||
|
def self.generate(type, report_path, data)
|
||||||
|
if type == 'simplecov'
|
||||||
|
simplecov(report_path, data)
|
||||||
|
elsif type == 'jest'
|
||||||
|
jest(report_path, data)
|
||||||
|
else
|
||||||
|
raise 'InvalidCoverageReportType'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.simplecov(report_path, data)
|
||||||
|
report = JSON.parse(report_path)
|
||||||
|
minumum_percent = data[:min]
|
||||||
|
covered_percent = report.dig('result', 'covered_percent')
|
||||||
|
{ 'lines' => { 'covered_percent' => covered_percent, 'minumum_percent' => minumum_percent } }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.jest(report_path, data)
|
||||||
|
report = JSON.parse(report_path)
|
||||||
|
minumum_percent = data[:min]
|
||||||
|
covered_percent = report.dig('result', 'covered_percent')
|
||||||
|
{ 'lines' => { 'covered_percent' => covered_percent, 'minumum_percent' => minumum_percent } }
|
||||||
|
end
|
||||||
|
end
|
||||||
14
lib/index.rb
14
lib/index.rb
@ -6,6 +6,7 @@ require 'time'
|
|||||||
require_relative './report_adapter'
|
require_relative './report_adapter'
|
||||||
require_relative './github_check_run_service'
|
require_relative './github_check_run_service'
|
||||||
require_relative './github_client'
|
require_relative './github_client'
|
||||||
|
require_relative './coverage_report'
|
||||||
|
|
||||||
def read_json(path)
|
def read_json(path)
|
||||||
JSON.parse(File.read(path))
|
JSON.parse(File.read(path))
|
||||||
@ -14,16 +15,15 @@ end
|
|||||||
@event_json = read_json(ENV['GITHUB_EVENT_PATH']) if ENV['GITHUB_EVENT_PATH']
|
@event_json = read_json(ENV['GITHUB_EVENT_PATH']) if ENV['GITHUB_EVENT_PATH']
|
||||||
@github_data = {
|
@github_data = {
|
||||||
sha: ENV['GITHUB_SHA'],
|
sha: ENV['GITHUB_SHA'],
|
||||||
token: ENV['GITHUB_TOKEN'],
|
token: ENV['INPUT_TOKEN'],
|
||||||
owner: ENV['GITHUB_REPOSITORY_OWNER'] || @event_json.dig('repository', 'owner', 'login'),
|
owner: ENV['GITHUB_REPOSITORY_OWNER'] || @event_json.dig('repository', 'owner', 'login'),
|
||||||
repo: ENV['GITHUB_REPOSITORY_NAME'] || @event_json.dig('repository', 'name')
|
repo: ENV['GITHUB_REPOSITORY_NAME'] || @event_json.dig('repository', 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
@report =
|
@coverage_type = ENV['INPUT_TYPE']
|
||||||
if ENV['REPORT_PATH']
|
@report_path = ENV['INPUT_RESULT_PATH']
|
||||||
read_json(ENV['REPORT_PATH'])
|
@data = { min: ENV['INPUT_MIN_COVERAGE'] }
|
||||||
else
|
|
||||||
Dir.chdir(ENV['GITHUB_WORKSPACE']) { JSON.parse(`brakeman -f json`) }
|
@report = CoverageReport.generate(@coverage_type, @report_path, @data)
|
||||||
end
|
|
||||||
|
|
||||||
GithubCheckRunService.new(@report, @github_data, ReportAdapter).run
|
GithubCheckRunService.new(@report, @github_data, ReportAdapter).run
|
||||||
|
|||||||
34
spec/fixtures/output/annotations.json
vendored
34
spec/fixtures/output/annotations.json
vendored
@ -1,34 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"path": "app/controllers/posts_controller.rb",
|
|
||||||
"start_line": 29,
|
|
||||||
"end_line": 29,
|
|
||||||
"annotation_level": "warning",
|
|
||||||
"title": "High - Evaluation",
|
|
||||||
"message": "User input in eval"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "app/controllers/posts_controller.rb",
|
|
||||||
"start_line": 18,
|
|
||||||
"end_line": 18,
|
|
||||||
"annotation_level": "warning",
|
|
||||||
"title": "High - MassAssignment",
|
|
||||||
"message": "Parameters should be whitelisted for mass assignment"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "app/controllers/posts_controller.rb",
|
|
||||||
"start_line": 19,
|
|
||||||
"end_line": 19,
|
|
||||||
"annotation_level": "warning",
|
|
||||||
"title": "High - MassAssignment",
|
|
||||||
"message": "Parameters should be whitelisted for mass assignment"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "app/controllers/posts_controller.rb",
|
|
||||||
"start_line": 13,
|
|
||||||
"end_line": 13,
|
|
||||||
"annotation_level": "warning",
|
|
||||||
"title": "Medium - SQL",
|
|
||||||
"message": "Possible SQL injection"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
Reference in New Issue
Block a user