Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pushed_branches_service.rb « merge_requests « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbe75305d922e074d3fb17616ad8c70490ce0e96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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?

      source_branches = project.source_of_merge_requests.open_and_closed
        .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