Commit b89d7c4d authored by Rémy Coutable's avatar Rémy Coutable

Introduce a new EE::Repository#insights_config_for method

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent eaba1acc
......@@ -103,5 +103,9 @@ module EE
possible_code_owner_blobs = ::Gitlab::CodeOwners::FILE_PATHS.map { |path| [ref, path] }
blobs_at(possible_code_owner_blobs).compact.first
end
def insights_config_for(sha)
blob_data_at(sha, ::Gitlab::Insights::CONFIG_FILE_PATH)
end
end
end
......@@ -2,6 +2,7 @@
module Gitlab
module Insights
CONFIG_FILE_PATH = '.gitlab/insights.yml'
COLOR_SCHEME = {
red: '#e6194b',
green: '#3cb44b',
......
......@@ -187,4 +187,25 @@ describe Repository do
.not_to change { ::Geo::RepositoryUpdatedEvent.count }
end
end
describe "#insights_config_for" do
context 'when no config file exists' do
it 'returns nil if does not exist' do
expect(repository.insights_config_for(repository.root_ref)).to be_nil
end
end
it 'returns nil for an empty repository' do
allow(repository).to receive(:empty?).and_return(true)
expect(repository.insights_config_for(repository.root_ref)).to be_nil
end
it 'returns a valid Insights config file' do
project = create(:project, :custom_repo, files: { Gitlab::Insights::CONFIG_FILE_PATH => '- key: monthlyBugsCreated' })
insights_config_blob = project.repository.blob_at(project.repository.root_ref, Gitlab::Insights::CONFIG_FILE_PATH)
expect(project.repository.insights_config_for(project.repository.root_ref)).to eq('- key: monthlyBugsCreated')
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