debian-mirror-gitlab/app/controllers/projects/registry/repositories_controller.rb

57 lines
1.5 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Projects
module Registry
class RepositoriesController < ::Projects::Registry::ApplicationController
before_action :authorize_update_container_image!, only: [:destroy]
before_action :ensure_root_container_repository!, only: [:index]
def index
@images = project.container_repositories
2019-12-21 20:55:43 +05:30
track_event(:list_repositories)
2018-03-17 18:26:18 +05:30
respond_to do |format|
format.html
format.json do
render json: ContainerRepositoriesSerializer
.new(project: project, current_user: current_user)
.represent(@images)
end
end
2017-08-17 22:00:37 +05:30
end
def destroy
2018-11-20 20:47:30 +05:30
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id)
2019-12-21 20:55:43 +05:30
track_event(:delete_repository)
2018-11-20 20:47:30 +05:30
respond_to do |format|
format.json { head :no_content }
2017-08-17 22:00:37 +05:30
end
end
private
def image
@image ||= project.container_repositories.find(params[:id])
end
##
# Container repository object for root project path.
#
# Needed to maintain a backwards compatibility.
#
def ensure_root_container_repository!
2018-11-20 20:47:30 +05:30
::ContainerRegistry::Path.new(@project.full_path).tap do |path|
2017-08-17 22:00:37 +05:30
break if path.has_repository?
2018-11-20 20:47:30 +05:30
::ContainerRepository.build_from_path(path).tap do |repository|
2017-08-17 22:00:37 +05:30
repository.save! if repository.has_tags?
end
end
2019-09-30 21:07:59 +05:30
rescue ContainerRegistry::Path::InvalidRegistryPathError
@character_error = true
2017-08-17 22:00:37 +05:30
end
end
end
end