2020-04-21 11:21:10 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MergeRequests
|
|
|
|
class PushedBranchesService < MergeRequests::BaseService
|
|
|
|
include ::Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
# Skip moving this logic into models since it's too specific
|
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def execute
|
|
|
|
return [] if branch_names.blank?
|
|
|
|
|
2020-07-21 08:09:30 -04:00
|
|
|
source_branches = project.source_of_merge_requests.open_and_closed
|
2020-04-21 11:21:10 -04:00
|
|
|
.from_source_branches(branch_names).pluck(:source_branch)
|
|
|
|
|
|
|
|
target_branches = project.merge_requests.opened
|
|
|
|
.by_target_branch(branch_names).distinct.pluck(:target_branch)
|
|
|
|
|
|
|
|
source_branches.concat(target_branches).to_set
|
|
|
|
end
|
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def branch_names
|
|
|
|
strong_memoize(:branch_names) do
|
|
|
|
params[:changes].map do |change|
|
|
|
|
Gitlab::Git.branch_name(change[:ref])
|
|
|
|
end.compact
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|