Commit 3c6830de authored by Matt Kasa's avatar Matt Kasa

Add an exact_name param to the GroupPackagesFinder

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/333790
parent 664586f7
......@@ -54,6 +54,12 @@ module Packages
packages.search_by_name(params[:package_name])
end
def filter_by_exact_package_name(packages)
return packages unless params[:package_name].present?
packages.with_name(params[:package_name])
end
def filter_by_package_version(packages)
return packages unless params[:package_version].present?
......
......@@ -4,7 +4,7 @@ module Packages
class GroupPackagesFinder
include ::Packages::FinderHelper
def initialize(current_user, group, params = { exclude_subgroups: false, order_by: 'created_at', sort: 'asc' })
def initialize(current_user, group, params = { exclude_subgroups: false, exact_name: false, order_by: 'created_at', sort: 'asc' })
@current_user = current_user
@group = group
@params = params
......@@ -30,7 +30,7 @@ module Packages
packages = filter_with_version(packages)
packages = filter_by_package_type(packages)
packages = filter_by_package_name(packages)
packages = (params[:exact_name] ? filter_by_exact_package_name(packages) : filter_by_package_name(packages))
packages = filter_by_package_version(packages)
installable_only ? packages.installable : filter_by_status(packages)
end
......
......@@ -147,6 +147,19 @@ RSpec.describe Packages::GroupPackagesFinder do
end
end
context 'with exact package_name' do
let_it_be(:named_package) { create(:maven_package, project: project, name: 'maven') }
let_it_be(:other_package) { create(:maven_package, project: project, name: 'maventoo') }
let(:params) { { exact_name: true, package_name: package_name } }
context 'as complete name' do
let(:package_name) { 'maven' }
it { is_expected.to match_array([named_package]) }
end
end
it_behaves_like 'concerning versionless param'
it_behaves_like 'concerning package statuses'
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment