debian-mirror-gitlab/lib/api/entities/package.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
2.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module API
module Entities
class Package < Grape::Entity
include ::API::Helpers::RelatedResourcesHelpers
2023-01-13 00:05:48 +05:30
include ::Routing::PackagesHelper
2020-07-28 23:09:34 +05:30
extend ::API::Entities::EntityHelpers
2023-01-13 00:05:48 +05:30
expose :id, documentation: { type: 'integer', example: 1 }
2021-01-03 14:25:43 +05:30
2023-01-13 00:05:48 +05:30
expose :name, documentation: { type: 'string', example: '@foo/bar' } do |package|
2021-01-03 14:25:43 +05:30
if package.conan?
package.conan_recipe
else
package.name
end
end
expose :conan_package_name, if: ->(package) { package.conan? } do |package|
package.name
end
2023-01-13 00:05:48 +05:30
expose :version, documentation: { type: 'string', example: '1.0.3' }
expose :package_type, documentation: { type: 'string', example: 'npm' }
expose :status, documentation: { type: 'string', example: 'default' }
2020-07-28 23:09:34 +05:30
expose :_links do
2023-03-04 22:38:38 +05:30
expose :web_path, if: ->(package) { package.default? } do |package|
2023-01-13 00:05:48 +05:30
package_path(package)
2020-07-28 23:09:34 +05:30
end
expose :delete_api_path, if: can_destroy(:package, &:project) do |package|
expose_url api_v4_projects_packages_path(package_id: package.id, id: package.project_id)
end
end
2023-01-13 00:05:48 +05:30
expose :created_at, documentation: { type: 'dateTime', example: '2022-09-16T12:47:31.949Z' }
expose :last_downloaded_at, documentation: { type: 'dateTime', example: '2022-09-19T11:32:35.169Z' }
expose :project_id, documentation: { type: 'integer', example: 2 }, if: ->(_, opts) { opts[:group] }
expose :project_path, documentation: { type: 'string', example: 'gitlab/foo/bar' }, if: ->(obj, opts) do
opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project)
end
2020-07-28 23:09:34 +05:30
expose :tags
2021-01-29 00:20:46 +05:30
expose :pipeline, if: ->(package) { package.original_build_info }, using: Package::Pipeline
expose :pipelines, if: ->(package) { package.pipelines.present? }, using: Package::Pipeline
2020-07-28 23:09:34 +05:30
2020-11-24 15:15:51 +05:30
expose :versions, using: ::API::Entities::PackageVersion, unless: ->(_, opts) { opts[:collection] }
2020-07-28 23:09:34 +05:30
private
def project_path
object.project.full_path
end
end
end
end