Class: Ci::PipelinesForMergeRequestFinder

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/finders/ci/pipelines_for_merge_request_finder.rb

Overview

A state object to centralize logic related to merge request pipelines

Constant Summary collapse

COMMITS_LIMIT =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(merge_request, current_user) ⇒ PipelinesForMergeRequestFinder

Returns a new instance of PipelinesForMergeRequestFinder.



10
11
12
13
# File 'app/finders/ci/pipelines_for_merge_request_finder.rb', line 10

def initialize(merge_request, current_user)
  @merge_request = merge_request
  @current_user = current_user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



15
16
17
# File 'app/finders/ci/pipelines_for_merge_request_finder.rb', line 15

def current_user
  @current_user
end

#merge_requestObject (readonly)

Returns the value of attribute merge_request.



15
16
17
# File 'app/finders/ci/pipelines_for_merge_request_finder.rb', line 15

def merge_request
  @merge_request
end

Instance Method Details

#allObject

Fetch all pipelines without permission check.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/finders/ci/pipelines_for_merge_request_finder.rb', line 33

def all
  strong_memoize(:all_pipelines) do
    next Ci::Pipeline.none unless source_project

    pipelines =
      if merge_request.persisted?
        all_pipelines_for_merge_request
      else
        triggered_for_branch.for_sha(commit_shas)
      end

    sort(pipelines)
  end
end

#executeObject

Fetch all pipelines that the user can read.



20
21
22
23
24
25
26
27
28
29
30
# File 'app/finders/ci/pipelines_for_merge_request_finder.rb', line 20

def execute
  if can_read_pipeline_in_target_project? && can_read_pipeline_in_source_project?
    all
  elsif can_read_pipeline_in_source_project?
    all.for_project(merge_request.source_project)
  elsif can_read_pipeline_in_target_project?
    all.for_project(merge_request.target_project)
  else
    Ci::Pipeline.none
  end
end