Commit c5d09610 authored by Imre Farkas's avatar Imre Farkas

Merge branch 'mo-fix-codequality-comparer' into 'master'

Fix code quality report comparer

See merge request gitlab-org/gitlab!55123
parents 18d6b770 e36455ae
......@@ -5,7 +5,7 @@ module Gitlab
module Reports
class CodequalityReportsComparer < ReportsComparer
def initialize(base_report, head_report)
@base_report = base_report || CodequalityReports.new
@base_report = base_report
@head_report = head_report
end
......@@ -15,12 +15,16 @@ module Gitlab
def existing_errors
strong_memoize(:existing_errors) do
next [] if not_found?
base_report.all_degradations & head_report.all_degradations
end
end
def new_errors
strong_memoize(:new_errors) do
next [] if not_found?
fingerprints = head_report.degradations.keys - base_report.degradations.keys
head_report.degradations.fetch_values(*fingerprints)
end
......@@ -28,6 +32,8 @@ module Gitlab
def resolved_errors
strong_memoize(:resolved_errors) do
next [] if not_found?
fingerprints = base_report.degradations.keys - head_report.degradations.keys
base_report.degradations.fetch_values(*fingerprints)
end
......
......@@ -18,10 +18,10 @@ module Gitlab
end
def status
if success?
STATUS_SUCCESS
elsif base_report.nil? || head_report.nil?
if base_report.nil? || head_report.nil?
STATUS_NOT_FOUND
elsif success?
STATUS_SUCCESS
else
STATUS_FAILED
end
......@@ -54,6 +54,10 @@ module Gitlab
def total_count
existing_errors.size + new_errors.size
end
def not_found?
status == STATUS_NOT_FOUND
end
end
end
end
......
......@@ -27,6 +27,22 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityReportsComparer do
expect(report_status).to eq(described_class::STATUS_SUCCESS)
end
end
context 'when head report does not exist' do
let(:head_report) { nil }
it 'returns status not found' do
expect(report_status).to eq(described_class::STATUS_NOT_FOUND)
end
end
context 'when base report does not exist' do
let(:base_report) { nil }
it 'returns status success' do
expect(report_status).to eq(described_class::STATUS_NOT_FOUND)
end
end
end
describe '#errors_count' do
......@@ -93,6 +109,14 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityReportsComparer do
expect(resolved_count).to be_zero
end
end
context 'when base report is nil' do
let(:base_report) { nil }
it 'returns zero' do
expect(resolved_count).to be_zero
end
end
end
describe '#total_count' do
......@@ -140,6 +164,14 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityReportsComparer do
expect(total_count).to eq(2)
end
end
context 'when base report is nil' do
let(:base_report) { nil }
it 'returns zero' do
expect(total_count).to be_zero
end
end
end
describe '#existing_errors' do
......@@ -177,6 +209,14 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityReportsComparer do
expect(existing_errors).to be_empty
end
end
context 'when base report is nil' do
let(:base_report) { nil }
it 'returns an empty array' do
expect(existing_errors).to be_empty
end
end
end
describe '#new_errors' do
......@@ -213,6 +253,14 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityReportsComparer do
expect(new_errors).to eq([degradation_1])
end
end
context 'when base report is nil' do
let(:base_report) { nil }
it 'returns an empty array' do
expect(new_errors).to be_empty
end
end
end
describe '#resolved_errors' do
......@@ -250,5 +298,13 @@ RSpec.describe Gitlab::Ci::Reports::CodequalityReportsComparer do
expect(resolved_errors).to be_empty
end
end
context 'when base report is nil' do
let(:base_report) { nil }
it 'returns an empty array' do
expect(resolved_errors).to be_empty
end
end
end
end
......@@ -49,10 +49,6 @@ RSpec.describe Gitlab::Ci::Reports::ReportsComparer do
context 'when base_report is nil' do
let(:base_report) { nil }
before do
allow(comparer).to receive(:success?).and_return(false)
end
it 'returns status not_found' do
expect(status).to eq('not_found')
end
......@@ -61,10 +57,6 @@ RSpec.describe Gitlab::Ci::Reports::ReportsComparer do
context 'when head_report is nil' do
let(:head_report) { nil }
before do
allow(comparer).to receive(:success?).and_return(false)
end
it 'returns status not_found' do
expect(status).to eq('not_found')
end
......@@ -118,4 +110,22 @@ RSpec.describe Gitlab::Ci::Reports::ReportsComparer do
expect { total_count }.to raise_error(NotImplementedError)
end
end
describe '#not_found?' do
subject(:not_found) { comparer.not_found? }
context 'when base report is nil' do
let(:base_report) { nil }
it { is_expected.to be_truthy }
end
context 'when base report exists' do
before do
allow(comparer).to receive(:success?).and_return(true)
end
it { is_expected.to be_falsey }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment