diff --git a/lib/report_adapter.rb b/lib/report_adapter.rb index 0287ab0..ea34a20 100644 --- a/lib/report_adapter.rb +++ b/lib/report_adapter.rb @@ -7,15 +7,32 @@ class ReportAdapter ANNOTATION_LEVEL = { notice: 'notice', warning: 'warning', failure: 'failure' }.freeze def conslusion(report) - CONCLUSION_TYPES[:success] + lines_covered_percent(report) >= lines_minimum_percent(report).to_f ? CONCLUSION_TYPES[:success] : CONCLUSION_TYPES[:failure] end def summary(report) - "**Coverage**: #{report.dig('result', 'covered_percent')}%" + "**Coverage**:\n\n#{table_head}\n| Lines | #{lines_covered_percent(report)}% | #{lines_minimum_percent(report)}% |\n#{table_footer}\n" end - def annotations(report) + def annotations(_report) [] end + + private + def table_head + "| Type | covered | minimum |\n| ----- | ------- | ------- |" + end + + def table_footer + '| | | |' + end + + def lines_covered_percent(report) + @lines_covered_percent ||= report.dig('lines', 'covered_percent') + end + + def lines_minimum_percent(report) + @lines_minimum_percent ||= report.dig('lines', 'minumum_percent') + end end end diff --git a/spec/fixtures/output/summary.md b/spec/fixtures/output/summary.md index 1f35bb5..61b342c 100644 --- a/spec/fixtures/output/summary.md +++ b/spec/fixtures/output/summary.md @@ -1,5 +1,6 @@ -**Brakeman Report**: -4 security warnings -- [Evaluation](https://brakemanscanner.org/docs/warning_types/dangerous_eval/) -- [MassAssignment](https://brakemanscanner.org/docs/warning_types/mass_assignment/) -- [SQL](https://brakemanscanner.org/docs/warning_types/sql_injection/) +**Coverage**: + +| Type | covered | minimum | +| ----- | ------- | ------- | +| Lines | 80% | 80% | +| | | | diff --git a/spec/github_check_run_service_spec.rb b/spec/github_check_run_service_spec.rb index fbd86b1..b76cb51 100644 --- a/spec/github_check_run_service_spec.rb +++ b/spec/github_check_run_service_spec.rb @@ -3,9 +3,11 @@ require './spec/spec_helper' describe GithubCheckRunService do - let(:brakeman_report) { JSON(File.read('./spec/fixtures/report.json')) } + let(:report) do + { 'lines' => { 'covered_percent' => 80, 'minumum_percent' => 80 } } + end let(:github_data) { { sha: 'sha', token: 'token', owner: 'owner', repo: 'repository_name' } } - let(:service) { GithubCheckRunService.new(brakeman_report, github_data, ReportAdapter) } + let(:service) { GithubCheckRunService.new(report, github_data, ReportAdapter) } it '#run' do stub_request(:any, 'https://api.github.com/repos/owner/repository_name/check-runs/id') diff --git a/spec/report_adapter_spec.rb b/spec/report_adapter_spec.rb index 132dec7..137c0e8 100644 --- a/spec/report_adapter_spec.rb +++ b/spec/report_adapter_spec.rb @@ -3,12 +3,8 @@ require './spec/spec_helper' describe ReportAdapter do - let(:brakeman_report) do - JSON(File.read('./spec/fixtures/report.json')) - end - - let(:spec_annotations) do - JSON(File.read('./spec/fixtures/output/annotations.json')) + let(:report) do + { 'lines' => { 'covered_percent' => 80, 'minumum_percent' => 80 } } end let(:spec_summary) do @@ -18,17 +14,17 @@ describe ReportAdapter do let(:adapter) { ReportAdapter } it '.conslusion' do - result = adapter.conslusion(brakeman_report) - expect(result).to eq('failure') + result = adapter.conslusion(report) + expect(result).to eq('success') end it '.summary' do - result = adapter.summary(brakeman_report) + result = adapter.summary(report) expect(result).to eq(spec_summary) end it '.annotations' do - result = adapter.annotations(brakeman_report) - expect(result).to eq(spec_annotations) + result = adapter.annotations(report) + expect(result).to eq([]) end end