Add minor improvements to container registry code

This commit is contained in:
Grzegorz Bizon 2017-04-06 10:23:51 +02:00
parent 82dea6cffe
commit 714c408f22
2 changed files with 8 additions and 6 deletions

View File

@ -15,15 +15,13 @@ module Projects
private
def repository
def image
@image ||= project.container_repositories
.find(params[:repository_id])
end
def tag
return render_404 unless params[:id].present?
@tag ||= repository.tag(params[:id])
@tag ||= image.tag(params[:id])
end
end
end

View File

@ -1,6 +1,6 @@
module ContainerRegistry
##
# Class reponsible for extracting project and repository name from
# Class responsible for extracting project and repository name from
# image repository path provided by a containers registry API response.
#
# Example:
@ -12,6 +12,8 @@ module ContainerRegistry
class Path
InvalidRegistryPathError = Class.new(StandardError)
LEVELS_SUPPORTED = 3
def initialize(path)
@path = path
end
@ -50,7 +52,9 @@ module ContainerRegistry
end
def repository_project
@project ||= Project.where_full_path_in(nodes.first(3)).first
@project ||= Project
.where_full_path_in(nodes.first(LEVELS_SUPPORTED))
.first
end
def repository_name