Welcome to mirror list, hosted at ThFree Co, Russian Federation.

package_finder.rb « nuget « packages « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 064698d3c378de082213138c503abb686b3233f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

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 = 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
end