summaryrefslogtreecommitdiff
path: root/app/presenters/packages/pypi/simple_package_versions_presenter.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
commit0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch)
tree7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /app/presenters/packages/pypi/simple_package_versions_presenter.rb
parent72123183a20411a36d607d70b12d57c484394c8e (diff)
downloadgitlab-ce-0ea3fcec397b69815975647f5e2aa5fe944a8486.tar.gz
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'app/presenters/packages/pypi/simple_package_versions_presenter.rb')
-rw-r--r--app/presenters/packages/pypi/simple_package_versions_presenter.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/app/presenters/packages/pypi/simple_package_versions_presenter.rb b/app/presenters/packages/pypi/simple_package_versions_presenter.rb
new file mode 100644
index 00000000000..0baa0714463
--- /dev/null
+++ b/app/presenters/packages/pypi/simple_package_versions_presenter.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+# Display package version data acording to PyPI
+# Simple API: https://warehouse.pypa.io/api-reference/legacy/#simple-project-api
+# Generates the HTML body for PyPI simple API.
+# Basically a list of package download links for a specific
+# package
+module Packages
+ module Pypi
+ class SimplePackageVersionsPresenter < SimplePresenterBase
+ private
+
+ def links
+ refs = []
+
+ available_packages.each_batch do |batch|
+ batch.each do |package|
+ package_files = package.installable_package_files
+
+ package_files.each do |file|
+ url = build_pypi_package_file_path(file)
+
+ refs << package_link(url, package.pypi_metadatum.required_python, file.file_name)
+ end
+ end
+ end
+
+ refs.join
+ end
+
+ def build_pypi_package_file_path(file)
+ params = {
+ id: @project_or_group.id,
+ sha256: file.file_sha256,
+ file_identifier: file.file_name
+ }
+
+ if project?
+ expose_url(
+ api_v4_projects_packages_pypi_files_file_identifier_path(
+ params, true
+ )
+ ) + "#sha256=#{file.file_sha256}"
+ elsif group?
+ expose_url(
+ api_v4_groups___packages_pypi_files_file_identifier_path(
+ params, true
+ )
+ ) + "#sha256=#{file.file_sha256}"
+ end
+ end
+
+ def body_name
+ @packages.first.name
+ end
+ end
+ end
+end