report adapter

This commit is contained in:
Miguel Savignano 2019-11-02 13:41:39 +01:00
parent d7c0892c88
commit 9247c263a3
4 changed files with 37 additions and 21 deletions

View File

@ -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

View File

@ -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% |
| | | |

View File

@ -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')

View File

@ -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