debian-mirror-gitlab/lib/api/package_files.rb

62 lines
1.8 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module API
2021-01-03 14:25:43 +05:30
class PackageFiles < ::API::Base
2020-07-28 23:09:34 +05:30
include PaginationParams
before do
authorize_packages_access!(user_project)
end
2021-01-29 00:20:46 +05:30
feature_category :package_registry
2020-07-28 23:09:34 +05:30
helpers ::API::Helpers::PackagesHelpers
params do
requires :id, type: String, desc: 'The ID of a project'
requires :package_id, type: Integer, desc: 'The ID of a package'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get all package files' do
detail 'This feature was introduced in GitLab 11.8'
success ::API::Entities::PackageFile
end
params do
use :pagination
end
get ':id/packages/:package_id/package_files' do
package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute
2021-12-11 22:18:48 +05:30
files = package.package_files
.preload_pipelines
present paginate(files), with: ::API::Entities::PackageFile
2020-07-28 23:09:34 +05:30
end
2021-06-08 01:23:25 +05:30
desc 'Remove a package file' do
detail 'This feature was introduced in GitLab 13.12'
end
params do
requires :package_file_id, type: Integer, desc: 'The ID of a package file'
end
delete ':id/packages/:package_id/package_files/:package_file_id' do
authorize_destroy_package!(user_project)
# We want to make sure the file belongs to the declared package
# so we look up the package before looking up the file.
package = ::Packages::PackageFinder
.new(user_project, params[:package_id]).execute
not_found! unless package
package_file = package.package_files.find_by_id(params[:package_file_id])
not_found! unless package_file
destroy_conditionally!(package_file)
end
2020-07-28 23:09:34 +05:30
end
end
end