Refine method for checking project registry tags
This commit is contained in:
parent
fc5eb31570
commit
a9b221d91a
2 changed files with 80 additions and 0 deletions
|
@ -406,6 +406,11 @@ class Project < ActiveRecord::Base
|
|||
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 @@ class Project < ActiveRecord::Base
|
|||
|
||||
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 @@ describe Project, models: true do
|
|||
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,
|
||||
|
|
Loading…
Reference in a new issue