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

59 lines
1.7 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
extend ::API::Entities::EntityHelpers
expose :id
2021-01-03 14:25:43 +05:30
expose :name do |package|
if package.conan?
package.conan_recipe
else
package.name
end
end
expose :conan_package_name, if: ->(package) { package.conan? } do |package|
package.name
end
2020-07-28 23:09:34 +05:30
expose :version
expose :package_type
2021-06-08 01:23:25 +05:30
expose :status
2020-07-28 23:09:34 +05:30
expose :_links do
2021-09-04 01:27:46 +05:30
expose :web_path do |package, opts|
if package.infrastructure_package?
::Gitlab::Routing.url_helpers.namespace_project_infrastructure_registry_path(opts[:namespace], package.project, package)
else
::Gitlab::Routing.url_helpers.project_package_path(package.project, package)
end
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
expose :created_at
expose :project_id, if: ->(_, opts) { opts[:group] }
expose :project_path, if: ->(obj, opts) { opts[:group] && Ability.allowed?(opts[:user], :read_project, obj.project) }
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