2020-07-10 15:09:07 +00:00
|
|
|
# frozen_string_literal: true
|
2021-01-12 03:10:47 +00:00
|
|
|
|
2020-07-10 15:09:07 +00:00
|
|
|
module Packages
|
|
|
|
module Maven
|
|
|
|
class PackageFinder
|
2021-03-30 09:10:51 +00:00
|
|
|
include ::Packages::FinderHelper
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
2020-07-10 15:09:07 +00:00
|
|
|
|
2021-03-30 09:10:51 +00:00
|
|
|
def initialize(path, current_user, project: nil, group: nil, order_by_package_file: false)
|
2020-07-10 15:09:07 +00:00
|
|
|
@path = path
|
|
|
|
@current_user = current_user
|
|
|
|
@project = project
|
|
|
|
@group = group
|
2021-03-30 09:10:51 +00:00
|
|
|
@order_by_package_file = order_by_package_file
|
2020-07-10 15:09:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
packages_with_path.last
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute!
|
|
|
|
packages_with_path.last!
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def base
|
2021-03-30 09:10:51 +00:00
|
|
|
if @project
|
2021-05-11 15:10:20 +00:00
|
|
|
packages_for_project(@project)
|
2021-03-30 09:10:51 +00:00
|
|
|
elsif @group
|
2021-05-11 15:10:20 +00:00
|
|
|
packages_visible_to_user(@current_user, within_group: @group)
|
2020-07-10 15:09:07 +00:00
|
|
|
else
|
2021-01-05 18:10:25 +00:00
|
|
|
::Packages::Package.none
|
2020-07-10 15:09:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def packages_with_path
|
2021-03-30 09:10:51 +00:00
|
|
|
matching_packages = base.only_maven_packages_with_path(@path, use_cte: @group.present?)
|
2021-04-22 18:10:13 +00:00
|
|
|
matching_packages = matching_packages.order_by_package_file if @order_by_package_file
|
2021-01-12 03:10:47 +00:00
|
|
|
|
|
|
|
matching_packages
|
|
|
|
end
|
2020-07-10 15:09:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|