2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-20 11:41:11 -04:00
|
|
|
class MergeRequestTargetProjectFinder
|
2017-12-11 09:21:06 -05:00
|
|
|
include FinderMethods
|
|
|
|
|
2017-09-20 11:41:11 -04:00
|
|
|
attr_reader :current_user, :source_project
|
|
|
|
|
2021-02-22 10:10:48 -05:00
|
|
|
def initialize(current_user: nil, source_project:, project_feature: :merge_requests)
|
2017-09-20 11:41:11 -04:00
|
|
|
@current_user = current_user
|
|
|
|
@source_project = source_project
|
2021-02-22 10:10:48 -05:00
|
|
|
@project_feature = project_feature
|
2017-09-20 11:41:11 -04:00
|
|
|
end
|
|
|
|
|
2019-12-17 04:07:48 -05:00
|
|
|
def execute(include_routes: false)
|
|
|
|
if source_project.fork_network
|
|
|
|
include_routes ? projects.inc_routes : projects
|
2017-09-20 11:41:11 -04:00
|
|
|
else
|
2021-02-22 10:10:48 -05:00
|
|
|
Project.id_in(source_project.id)
|
2017-09-20 11:41:11 -04:00
|
|
|
end
|
|
|
|
end
|
2019-12-17 04:07:48 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-02-22 10:10:48 -05:00
|
|
|
attr_reader :project_feature
|
|
|
|
|
2019-12-17 04:07:48 -05:00
|
|
|
def projects
|
|
|
|
source_project
|
|
|
|
.fork_network
|
|
|
|
.projects
|
|
|
|
.public_or_visible_to_user(current_user)
|
|
|
|
.non_archived
|
2021-02-22 10:10:48 -05:00
|
|
|
.with_feature_available_for_user(project_feature, current_user)
|
2019-12-17 04:07:48 -05:00
|
|
|
end
|
2017-09-20 11:41:11 -04:00
|
|
|
end
|