diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /app/presenters/packages/pypi/simple_index_presenter.rb | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'app/presenters/packages/pypi/simple_index_presenter.rb')
-rw-r--r-- | app/presenters/packages/pypi/simple_index_presenter.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/presenters/packages/pypi/simple_index_presenter.rb b/app/presenters/packages/pypi/simple_index_presenter.rb new file mode 100644 index 00000000000..ffe4eeb9585 --- /dev/null +++ b/app/presenters/packages/pypi/simple_index_presenter.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +# Display package repository index acording to PyPI +# Simple API: https://peps.python.org/pep-0503/ +module Packages + module Pypi + class SimpleIndexPresenter < SimplePresenterBase + private + + def links + refs = [] + + available_packages.each_batch do |batch| + batch.each do |package| + url = build_pypi_package_path(package) + + refs << package_link(url, package.pypi_metadatum.required_python, package.name) + end + end + + refs.join + end + + def build_pypi_package_path(package) + params = { + id: @project_or_group.id, + package_name: package.normalized_pypi_name + } + + if project? + expose_url( + api_v4_projects_packages_pypi_simple_package_name_path( + params, true + ) + ) + elsif group? + expose_url( + api_v4_groups___packages_pypi_simple_package_name_path( + params, true + ) + ) + end + end + + def body_name + @project_or_group.name + end + end + end +end |