2020-07-10 11:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Packages
|
|
|
|
class PackagesFinder
|
2021-02-17 07:09:26 -05:00
|
|
|
include ::Packages::FinderHelper
|
2020-07-10 11:09:07 -04:00
|
|
|
|
|
|
|
def initialize(project, params = {})
|
|
|
|
@project = project
|
|
|
|
@params = params
|
|
|
|
|
|
|
|
params[:order_by] ||= 'created_at'
|
|
|
|
params[:sort] ||= 'asc'
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2020-09-03 20:09:08 -04:00
|
|
|
packages = project.packages
|
2021-11-11 22:12:11 -05:00
|
|
|
.preload_pipelines
|
2020-09-03 20:09:08 -04:00
|
|
|
.including_project_route
|
|
|
|
.including_tags
|
2021-10-27 20:10:09 -04:00
|
|
|
|
2021-01-06 16:10:18 -05:00
|
|
|
packages = filter_with_version(packages)
|
2020-07-10 11:09:07 -04:00
|
|
|
packages = filter_by_package_type(packages)
|
|
|
|
packages = filter_by_package_name(packages)
|
2021-02-17 07:09:26 -05:00
|
|
|
packages = filter_by_status(packages)
|
2021-04-19 11:09:08 -04:00
|
|
|
order_packages(packages)
|
2020-07-10 11:09:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-02-17 07:09:26 -05:00
|
|
|
attr_reader :params, :project
|
2020-07-10 11:09:07 -04:00
|
|
|
|
|
|
|
def order_packages(packages)
|
|
|
|
packages.sort_by_attribute("#{params[:order_by]}_#{params[:sort]}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|