Commit a9b221d9 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Refine method for checking project registry tags

parent af16ec74e83d
......@@ -406,6 +406,11 @@ def container_registry_url
end
end
def has_container_registry_tags?
container_repositories.to_a.any?(&:has_tags?) ||
has_root_container_repository_tags?
end
def commit(ref = 'HEAD')
repository.commit(ref)
end
......@@ -1373,4 +1378,19 @@ def pending_delete_twin
Project.unscoped.where(pending_delete: true).find_by_full_path(path_with_namespace)
end
##
# This method is here because of support for legacy container repository
# which has exactly the same path like project does, but which might not be
# persisted in `container_repositories` table.
#
def has_root_container_repository_tags?
return false unless Gitlab.config.registry.enabled
ContainerRegistry::Path.new(self.full_path).tap do |path|
ContainerRepository.build_from_path(path).tap do |repository|
return repository.has_tags?
end
end
end
end
......@@ -1414,6 +1414,66 @@ def create_pipeline
end
end
describe '#has_container_registry_tags?' do
let(:project) { create(:empty_project) }
context 'when container registry is enabled' do
before { stub_container_registry_config(enabled: true) }
context 'when tags are present for multi-level registries' do
before do
create(:container_repository, project: project, name: 'image')
stub_container_registry_tags(repository: /image/,
tags: %w[latest rc1])
end
it 'should have image tags' do
expect(project).to have_container_registry_tags
end
end
context 'when tags are present for root repository' do
before do
stub_container_registry_tags(repository: project.full_path,
tags: %w[latest rc1 pre1])
end
it 'should have image tags' do
expect(project).to have_container_registry_tags
end
end
context 'when there are no tags at all' do
before do
stub_container_registry_tags(repository: :any, tags: [])
end
it 'should not have image tags' do
expect(project).not_to have_container_registry_tags
end
end
end
context 'when container registry is disabled' do
before { stub_container_registry_config(enabled: false) }
it 'should not have image tags' do
expect(project).not_to have_container_registry_tags
end
it 'should not check root repository tags' do
expect(project).not_to receive(:full_path)
expect(project).not_to have_container_registry_tags
end
it 'should iterate through container repositories' do
expect(project).to receive(:container_repositories)
expect(project).not_to have_container_registry_tags
end
end
end
describe '#latest_successful_builds_for' do
def create_pipeline(status = 'success')
create(:ci_pipeline, project: project,
......
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