debian-mirror-gitlab/app/finders/packages/nuget/package_finder.rb

53 lines
1.2 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
2021-03-08 18:12:59 +05:30
2020-07-28 23:09:34 +05:30
module Packages
module Nuget
class PackageFinder
2021-03-08 18:12:59 +05:30
include ::Packages::FinderHelper
2020-07-28 23:09:34 +05:30
MAX_PACKAGES_COUNT = 50
2021-03-08 18:12:59 +05:30
def initialize(current_user, project_or_group, package_name:, package_version: nil, limit: MAX_PACKAGES_COUNT)
@current_user = current_user
@project_or_group = project_or_group
2020-07-28 23:09:34 +05:30
@package_name = package_name
@package_version = package_version
@limit = limit
end
def execute
packages.limit_recent(@limit)
end
private
2021-03-08 18:12:59 +05:30
def base
if project?
@project_or_group.packages
elsif group?
packages_visible_to_user(@current_user, within_group: @project_or_group)
else
::Packages::Package.none
end
end
2020-07-28 23:09:34 +05:30
def packages
2021-03-08 18:12:59 +05:30
result = base.nuget
.has_version
.processed
.with_name_like(@package_name)
2020-07-28 23:09:34 +05:30
result = result.with_version(@package_version) if @package_version.present?
result
end
2021-03-08 18:12:59 +05:30
def project?
@project_or_group.is_a?(::Project)
end
def group?
@project_or_group.is_a?(::Group)
end
2020-07-28 23:09:34 +05:30
end
end
end