debian-mirror-gitlab/app/finders/merge_request_target_project_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
class MergeRequestTargetProjectFinder
2018-03-27 19:54:05 +05:30
include FinderMethods
2018-03-17 18:26:18 +05:30
attr_reader :current_user, :source_project
2023-03-04 22:38:38 +05:30
def initialize(source_project:, current_user: nil, project_feature: :merge_requests)
2018-03-17 18:26:18 +05:30
@current_user = current_user
@source_project = source_project
2021-04-17 20:07:23 +05:30
@project_feature = project_feature
2018-03-17 18:26:18 +05:30
end
2023-04-23 21:23:45 +05:30
def execute(search: nil, include_routes: false)
2020-01-01 13:55:28 +05:30
if source_project.fork_network
2023-04-23 21:23:45 +05:30
items = include_routes ? projects.inc_routes : projects
by_search(items, search)
2018-03-17 18:26:18 +05:30
else
2021-04-17 20:07:23 +05:30
Project.id_in(source_project.id)
2018-03-17 18:26:18 +05:30
end
end
2020-01-01 13:55:28 +05:30
private
2021-04-17 20:07:23 +05:30
attr_reader :project_feature
2020-01-01 13:55:28 +05:30
def projects
source_project
.fork_network
.projects
.public_or_visible_to_user(current_user)
.non_archived
2021-04-17 20:07:23 +05:30
.with_feature_available_for_user(project_feature, current_user)
2020-01-01 13:55:28 +05:30
end
2023-04-23 21:23:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
def by_search(items, search)
items.joins(:route).fuzzy_search(search, [Route.arel_table[:path], Route.arel_table[:name], :description])
end
# rubocop: enable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
end