diff options
Diffstat (limited to 'app/finders/packages/nuget/package_finder.rb')
-rw-r--r-- | app/finders/packages/nuget/package_finder.rb | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/app/finders/packages/nuget/package_finder.rb b/app/finders/packages/nuget/package_finder.rb index 23345f29198..064698d3c37 100644 --- a/app/finders/packages/nuget/package_finder.rb +++ b/app/finders/packages/nuget/package_finder.rb @@ -4,19 +4,43 @@ module Packages module Nuget class PackageFinder < ::Packages::GroupOrProjectPackageFinder MAX_PACKAGES_COUNT = 300 + FORCE_NORMALIZATION_CLIENT_VERSION = '>= 3' def execute + return ::Packages::Package.none unless @params[:package_name].present? + packages.limit_recent(@params[:limit] || MAX_PACKAGES_COUNT) end private def packages - result = base.nuget - .has_version - .with_name_like(@params[:package_name]) - result = result.with_case_insensitive_version(@params[:package_version]) if @params[:package_version].present? + result = find_by_name + find_by_version(result) + end + + def find_by_name + base + .nuget + .has_version + .with_case_insensitive_name(@params[:package_name]) + end + + def find_by_version(result) + return result if @params[:package_version].blank? + result + .with_nuget_version_or_normalized_version( + @params[:package_version], + with_normalized: Feature.enabled?(:nuget_normalized_version, @project_or_group) && + client_forces_normalized_version? + ) + end + + def client_forces_normalized_version? + return true if @params[:client_version].blank? + + VersionSorter.compare(FORCE_NORMALIZATION_CLIENT_VERSION, @params[:client_version]) <= 0 end end end |