Commit 034904f8 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '326008-adjust-codeowners-metric-for-archived-projects' into 'master'

Add codeowners metric handler for archived projects

See merge request gitlab-org/gitlab!60602
parents bca2a229 79403b9a
...@@ -108,7 +108,7 @@ module Analytics ...@@ -108,7 +108,7 @@ module Analytics
return unless Feature.enabled?(:analytics_devops_adoption_codeowners, segment.namespace, default_enabled: :yaml) return unless Feature.enabled?(:analytics_devops_adoption_codeowners, segment.namespace, default_enabled: :yaml)
snapshot_projects.count do |project| snapshot_projects.count do |project|
!Gitlab::CodeOwners::Loader.new(project, project.default_branch).empty_code_owners? !Gitlab::CodeOwners::Loader.new(project, project.default_branch || 'HEAD').empty_code_owners?
end end
end end
end end
......
...@@ -135,7 +135,7 @@ RSpec.describe Analytics::DevopsAdoption::SnapshotCalculator do ...@@ -135,7 +135,7 @@ RSpec.describe Analytics::DevopsAdoption::SnapshotCalculator do
end end
describe 'code_owners_used_count' do describe 'code_owners_used_count' do
let!(:project_with_code_owners) { create(:project, :repository, group: subgroup)} let!(:project_with_code_owners) { create(:project, :repository, group: subgroup) }
subject { data[:code_owners_used_count] } subject { data[:code_owners_used_count] }
...@@ -152,12 +152,24 @@ RSpec.describe Analytics::DevopsAdoption::SnapshotCalculator do ...@@ -152,12 +152,24 @@ RSpec.describe Analytics::DevopsAdoption::SnapshotCalculator do
it { is_expected.to eq nil } it { is_expected.to eq nil }
end end
context 'when there is no default branch' do
before do
allow_any_instance_of(Project).to receive(:default_branch).and_return(nil) # rubocop:disable RSpec/AnyInstanceOf
end
it 'uses HEAD as default value' do
expect(Gitlab::CodeOwners::Loader).to receive(:new).with(kind_of(Project), 'HEAD').thrice.and_call_original
expect(subject).to eq 0
end
end
end end
context 'when snapshot already exists' do context 'when snapshot already exists' do
subject(:data) { described_class.new(segment: segment, range_end: range_end, snapshot: snapshot).calculate } subject(:data) { described_class.new(segment: segment, range_end: range_end, snapshot: snapshot).calculate }
let(:snapshot) { create :devops_adoption_snapshot, segment: segment, issue_opened: true, merge_request_opened: false, total_projects_count: 1} let(:snapshot) { create :devops_adoption_snapshot, segment: segment, issue_opened: true, merge_request_opened: false, total_projects_count: 1 }
context 'for boolean metrics' do context 'for boolean metrics' do
let!(:fresh_merge_request) { create(:merge_request, source_project: project, created_at: 3.weeks.ago(range_end)) } let!(:fresh_merge_request) { create(:merge_request, source_project: project, created_at: 3.weeks.ago(range_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