debian-mirror-gitlab/app/presenters/packages/composer/packages_presenter.rb

52 lines
1.3 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Packages
module Composer
class PackagesPresenter
include API::Helpers::RelatedResourcesHelpers
def initialize(group, packages)
@group = group
@packages = packages
end
def root
2021-02-22 17:27:13 +05:30
path = api_v4_group___packages_composer_package_name_path({ id: @group.id, package_name: '%package%$%hash%', format: '.json' }, true)
2020-07-28 23:09:34 +05:30
{ 'packages' => [], 'provider-includes' => { 'p/%hash%.json' => { 'sha256' => provider_sha } }, 'providers-url' => path }
end
def provider
{ 'providers' => providers_map }
end
def package_versions(packages = @packages)
2021-03-08 18:12:59 +05:30
package_versions_index(packages).as_json
2020-07-28 23:09:34 +05:30
end
private
2021-03-08 18:12:59 +05:30
def package_versions_sha(packages = @packages)
package_versions_index(packages).sha
2020-07-28 23:09:34 +05:30
end
2021-03-08 18:12:59 +05:30
def package_versions_index(packages)
::Gitlab::Composer::VersionIndex.new(packages)
2020-07-28 23:09:34 +05:30
end
def providers_map
map = {}
@packages.group_by(&:name).each_pair do |package_name, packages|
map[package_name] = { 'sha256' => package_versions_sha(packages) }
end
map
end
def provider_sha
Digest::SHA256.hexdigest(provider.to_json)
end
end
end
end