Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/project_packages.rb')
-rw-r--r--lib/api/project_packages.rb50
1 files changed, 44 insertions, 6 deletions
diff --git a/lib/api/project_packages.rb b/lib/api/project_packages.rb
index 158ba7465f4..43bd15931ef 100644
--- a/lib/api/project_packages.rb
+++ b/lib/api/project_packages.rb
@@ -2,8 +2,11 @@
module API
class ProjectPackages < ::API::Base
+ include Gitlab::Utils::StrongMemoize
include PaginationParams
+ PIPELINE_COLUMNS = %i[id iid project_id sha ref status source created_at updated_at user_id].freeze
+
before do
authorize_packages_access!(user_project)
end
@@ -12,6 +15,13 @@ module API
urgency :low
helpers ::API::Helpers::PackagesHelpers
+ helpers do
+ def package
+ strong_memoize(:package) do # rubocop:disable Gitlab/StrongMemoizeAttr
+ ::Packages::PackageFinder.new(user_project, declared_params[:package_id]).execute
+ end
+ end
+ end
params do
requires :id, types: [String, Integer], desc: 'The ID or URL-encoded path of the project'
@@ -66,14 +76,45 @@ module API
end
route_setting :authentication, job_token_allowed: true
get ':id/packages/:package_id' do
- package = ::Packages::PackageFinder
- .new(user_project, params[:package_id]).execute
-
render_api_error!('Package not found', 404) unless package.default?
present package, with: ::API::Entities::Package, user: current_user, namespace: user_project.namespace
end
+ desc 'Get the pipelines for a single project package' do
+ detail 'This feature was introduced in GitLab 16.1'
+ success code: 200, model: ::API::Entities::Package::Pipeline
+ failure [
+ { code: 401, message: 'Unauthorized' },
+ { code: 403, message: 'Forbidden' },
+ { code: 404, message: 'Not Found' }
+ ]
+ tags %w[project_packages]
+ end
+ params do
+ use :pagination
+ requires :package_id, type: Integer, desc: 'The ID of a package'
+ optional :cursor, type: String, desc: 'Cursor for obtaining the next set of records'
+ # Overrides the original definition to add the `values: 1..20` restriction
+ optional :per_page, type: Integer, default: 20,
+ desc: 'Number of items per page', documentation: { example: 20 },
+ values: 1..20
+ end
+ route_setting :authentication, job_token_allowed: true
+ get ':id/packages/:package_id/pipelines' do
+ not_found!('Package not found') unless package.default?
+
+ params[:pagination] = 'keyset' # keyset is the only available pagination
+ pipelines = paginate_with_strategies(
+ package.build_infos.without_empty_pipelines,
+ paginator_params: { per_page: declared_params[:per_page], cursor: declared_params[:cursor] }
+ ) do |results|
+ ::Ci::Pipeline.id_in(results.map(&:pipeline_id)).select(PIPELINE_COLUMNS).order_id_desc
+ end
+
+ present pipelines, with: ::API::Entities::Package::Pipeline, user: current_user
+ end
+
desc 'Delete a project package' do
detail 'This feature was introduced in GitLab 11.9'
success code: 204
@@ -90,9 +131,6 @@ module API
delete ':id/packages/:package_id' do
authorize_destroy_package!(user_project)
- package = ::Packages::PackageFinder
- .new(user_project, params[:package_id]).execute
-
destroy_conditionally!(package) do |package|
::Packages::MarkPackageForDestructionService.new(container: package, current_user: current_user).execute
end