Commit b9e1b9cf authored by Adam Hegyi's avatar Adam Hegyi

Fix insights notice text with YAML anchors

parent 5c3ddecc
---
title: Fix incorrect notice text on insights page
merge_request: 31570
author:
type: fixed
...@@ -7,7 +7,7 @@ module Gitlab ...@@ -7,7 +7,7 @@ module Gitlab
def initialize(project:, insights_config:) def initialize(project:, insights_config:)
@project = project @project = project
@insights_config = insights_config.deep_dup @insights_config = insights_config_without_invalid_entries(insights_config.deep_dup)
end end
def filtered_config def filtered_config
...@@ -33,6 +33,11 @@ module Gitlab ...@@ -33,6 +33,11 @@ module Gitlab
def includes_project?(project_ids_or_paths) def includes_project?(project_ids_or_paths)
project_ids_or_paths.any? { |item| item == project.id || item == project.full_path } project_ids_or_paths.any? { |item| item == project.id || item == project.full_path }
end end
# filtering out leftover YAML anchor keys
def insights_config_without_invalid_entries(config)
config.reject { |_, page_config| page_config[:title].nil? && page_config[:charts].nil? }
end
end end
end end
end end
...@@ -30,6 +30,20 @@ describe Gitlab::Insights::ProjectInsightsConfig do ...@@ -30,6 +30,20 @@ describe Gitlab::Insights::ProjectInsightsConfig do
subject { described_class.new(project: project, insights_config: config) } subject { described_class.new(project: project, insights_config: config) }
context 'filtering out invalid config entries' do
let(:config_with_invalid_entry) { config.merge(".projectOnly": { projects: { only: [] } }) }
subject { described_class.new(project: project, insights_config: config_with_invalid_entry) }
it 'does not include invalid entry' do
expect(subject.filtered_config).to eq(config)
end
it 'does not show notice text' do
expect(subject.notice_text).to eq(nil)
end
end
context 'when no projects.only filter present' do context 'when no projects.only filter present' do
it 'does not change the config' do it 'does not change the config' do
expect(subject.filtered_config).to eq(config) expect(subject.filtered_config).to eq(config)
...@@ -51,7 +65,7 @@ describe Gitlab::Insights::ProjectInsightsConfig do ...@@ -51,7 +65,7 @@ describe Gitlab::Insights::ProjectInsightsConfig do
expect(subject.filtered_config[:item1][:charts]).to eq([chart1]) expect(subject.filtered_config[:item1][:charts]).to eq([chart1])
end end
it 'has notice text' do it 'does not have a notice text' do
expect(subject.notice_text).not_to eq(nil) expect(subject.notice_text).not_to eq(nil)
end 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