Class: Ci::PipelinesFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/ci/pipelines_finder.rb

Constant Summary collapse

ALLOWED_INDEXED_COLUMNS =
%w[id status ref updated_at user_id].freeze
ALLOWED_SCOPES =
{
  RUNNING: 'running',
  PENDING: 'pending',
  FINISHED: 'finished',
  BRANCHES: 'branches',
  TAGS: 'tags'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, current_user, params = {}) ⇒ PipelinesFinder

Returns a new instance of PipelinesFinder.


16
17
18
19
20
21
# File 'app/finders/ci/pipelines_finder.rb', line 16

def initialize(project, current_user, params = {})
  @project = project
  @current_user = current_user
  @pipelines = project.all_pipelines
  @params = params
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.


5
6
7
# File 'app/finders/ci/pipelines_finder.rb', line 5

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.


5
6
7
# File 'app/finders/ci/pipelines_finder.rb', line 5

def params
  @params
end

#pipelinesObject (readonly)

Returns the value of attribute pipelines.


5
6
7
# File 'app/finders/ci/pipelines_finder.rb', line 5

def pipelines
  @pipelines
end

#projectObject (readonly)

Returns the value of attribute project.


5
6
7
# File 'app/finders/ci/pipelines_finder.rb', line 5

def project
  @project
end

Instance Method Details

#executeObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/finders/ci/pipelines_finder.rb', line 23

def execute
  unless Ability.allowed?(current_user, :read_pipeline, project)
    return Ci::Pipeline.none
  end

  items = pipelines
  items = items.no_child unless params[:iids].present?
  items = by_iids(items)
  items = by_scope(items)
  items = by_status(items)
  items = by_ref(items)
  items = by_sha(items)
  items = by_username(items)
  items = by_yaml_errors(items)
  items = by_updated_at(items)
  items = by_source(items)

  sort_items(items)
end