2020-07-21 08:09:30 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PackagesHelper
|
2022-01-07 13:16:06 -05:00
|
|
|
include ::API::Helpers::RelatedResourcesHelpers
|
|
|
|
|
2020-07-21 08:09:30 -04:00
|
|
|
def package_sort_path(options = {})
|
|
|
|
"#{request.path}?#{options.to_param}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def nuget_package_registry_url(project_id)
|
|
|
|
expose_url(api_v4_projects_packages_nuget_index_path(id: project_id, format: '.json'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_registry_instance_url(registry_type)
|
|
|
|
expose_url("api/#{::API::API.version}/packages/#{registry_type}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_registry_project_url(project_id, registry_type = :maven)
|
|
|
|
project_api_path = expose_path(api_v4_projects_path(id: project_id))
|
|
|
|
package_registry_project_path = "#{project_api_path}/packages/#{registry_type}"
|
|
|
|
expose_url(package_registry_project_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def package_from_presenter(package)
|
|
|
|
presenter = ::Packages::Detail::PackagePresenter.new(package)
|
|
|
|
|
|
|
|
presenter.detail_view.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def pypi_registry_url(project_id)
|
|
|
|
full_url = expose_url(api_v4_projects_packages_pypi_simple_package_name_path({ id: project_id, package_name: '' }, true))
|
|
|
|
full_url.sub!('://', '://__token__:<your_personal_token>@')
|
|
|
|
end
|
|
|
|
|
2020-08-11 08:09:55 -04:00
|
|
|
def composer_registry_url(group_id)
|
|
|
|
expose_url(api_v4_group___packages_composer_packages_path(id: group_id, format: '.json'))
|
|
|
|
end
|
|
|
|
|
2020-10-13 08:08:41 -04:00
|
|
|
def composer_config_repository_name(group_id)
|
|
|
|
"#{Gitlab.config.gitlab.host}/#{group_id}"
|
|
|
|
end
|
|
|
|
|
2020-09-30 08:09:53 -04:00
|
|
|
def track_package_event(event_name, scope, **args)
|
|
|
|
::Packages::CreateEventService.new(nil, current_user, event_name: event_name, scope: scope).execute
|
2021-03-16 08:11:31 -04:00
|
|
|
category = args.delete(:category) || self.class.name
|
|
|
|
::Gitlab::Tracking.event(category, event_name.to_s, **args)
|
2020-09-30 08:09:53 -04:00
|
|
|
end
|
2021-06-14 11:09:48 -04:00
|
|
|
|
2022-03-31 14:08:39 -04:00
|
|
|
def show_cleanup_policy_link(project)
|
2021-06-14 11:09:48 -04:00
|
|
|
Gitlab.com? &&
|
|
|
|
Gitlab.config.registry.enabled &&
|
2021-07-15 08:09:01 -04:00
|
|
|
project.feature_available?(:container_registry, current_user) &&
|
2021-06-14 11:09:48 -04:00
|
|
|
project.container_expiration_policy.nil? &&
|
|
|
|
project.container_repositories.exists?
|
|
|
|
end
|
2022-07-19 14:09:21 -04:00
|
|
|
|
|
|
|
def show_container_registry_settings(project)
|
|
|
|
Gitlab.config.registry.enabled &&
|
|
|
|
Ability.allowed?(current_user, :admin_container_image, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_package_registry_settings(project)
|
|
|
|
Gitlab.config.packages.enabled &&
|
|
|
|
Ability.allowed?(current_user, :admin_package, project)
|
|
|
|
end
|
2022-08-16 02:10:05 -04:00
|
|
|
|
|
|
|
def cleanup_settings_data
|
|
|
|
{
|
|
|
|
project_id: @project.id,
|
|
|
|
project_path: @project.full_path,
|
|
|
|
cadence_options: cadence_options.to_json,
|
|
|
|
keep_n_options: keep_n_options.to_json,
|
|
|
|
older_than_options: older_than_options.to_json,
|
|
|
|
is_admin: current_user&.admin.to_s,
|
|
|
|
admin_settings_path: ci_cd_admin_application_settings_path(anchor: 'js-registry-settings'),
|
2022-09-14 02:11:48 -04:00
|
|
|
project_settings_path: project_settings_packages_and_registries_path(@project),
|
2022-08-16 02:10:05 -04:00
|
|
|
enable_historic_entries: container_expiration_policies_historic_entry_enabled?.to_s,
|
|
|
|
help_page_path: help_page_path('user/packages/container_registry/reduce_container_registry_storage', anchor: 'cleanup-policy'),
|
|
|
|
show_cleanup_policy_link: show_cleanup_policy_link(@project).to_s,
|
|
|
|
tags_regex_help_page_path: help_page_path('user/packages/container_registry/reduce_container_registry_storage', anchor: 'regex-pattern-examples')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def settings_data
|
|
|
|
cleanup_settings_data.merge(
|
|
|
|
show_container_registry_settings: show_container_registry_settings(@project).to_s,
|
2022-09-09 05:14:13 -04:00
|
|
|
show_package_registry_settings: show_package_registry_settings(@project).to_s,
|
|
|
|
cleanup_settings_path: cleanup_image_tags_project_settings_packages_and_registries_path(@project)
|
2022-08-16 02:10:05 -04:00
|
|
|
)
|
|
|
|
end
|
2020-07-21 08:09:30 -04:00
|
|
|
end
|