2020-07-10 15:09:07 +00:00
|
|
|
# frozen_string_literal: true
|
2020-12-29 12:10:19 +00:00
|
|
|
|
2020-07-10 15:09:07 +00:00
|
|
|
module Packages
|
|
|
|
module Nuget
|
|
|
|
class PackageFinder
|
2020-12-29 12:10:19 +00:00
|
|
|
include ::Packages::FinderHelper
|
|
|
|
|
2020-07-10 15:09:07 +00:00
|
|
|
MAX_PACKAGES_COUNT = 50
|
|
|
|
|
2020-12-29 12:10:19 +00:00
|
|
|
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-10 15:09:07 +00:00
|
|
|
@package_name = package_name
|
|
|
|
@package_version = package_version
|
|
|
|
@limit = limit
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
packages.limit_recent(@limit)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-12-29 12:10:19 +00:00
|
|
|
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-10 15:09:07 +00:00
|
|
|
def packages
|
2020-12-29 12:10:19 +00:00
|
|
|
result = base.nuget
|
|
|
|
.has_version
|
|
|
|
.processed
|
|
|
|
.with_name_like(@package_name)
|
2020-07-10 15:09:07 +00:00
|
|
|
result = result.with_version(@package_version) if @package_version.present?
|
|
|
|
result
|
|
|
|
end
|
2020-12-29 12:10:19 +00:00
|
|
|
|
|
|
|
def project?
|
|
|
|
@project_or_group.is_a?(::Project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def group?
|
|
|
|
@project_or_group.is_a?(::Group)
|
|
|
|
end
|
2020-07-10 15:09:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|