Commit a9b221d9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refine method for checking project registry tags

parent fc5eb315
...@@ -406,6 +406,11 @@ class Project < ActiveRecord::Base ...@@ -406,6 +406,11 @@ class Project < ActiveRecord::Base
end end
end end
def has_container_registry_tags?
container_repositories.to_a.any?(&:has_tags?) ||
has_root_container_repository_tags?
end
def commit(ref = 'HEAD') def commit(ref = 'HEAD')
repository.commit(ref) repository.commit(ref)
end end
...@@ -1373,4 +1378,19 @@ class Project < ActiveRecord::Base ...@@ -1373,4 +1378,19 @@ class Project < ActiveRecord::Base
Project.unscoped.where(pending_delete: true).find_by_full_path(path_with_namespace) Project.unscoped.where(pending_delete: true).find_by_full_path(path_with_namespace)
end 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 end
...@@ -1414,6 +1414,66 @@ describe Project, models: true do ...@@ -1414,6 +1414,66 @@ describe Project, models: true do
end end
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 describe '#latest_successful_builds_for' do
def create_pipeline(status = 'success') def create_pipeline(status = 'success')
create(:ci_pipeline, project: project, 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