Class: Ci::PipelinesFinder

Inherits:
Object
  • Object
show all
Includes:
UpdatedAtFilter
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

Methods included from UpdatedAtFilter

#by_updated_at

Constructor Details

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

Returns a new instance of PipelinesFinder.



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

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.



7
8
9
# File 'app/finders/ci/pipelines_finder.rb', line 7

def current_user
  @current_user
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'app/finders/ci/pipelines_finder.rb', line 7

def params
  @params
end

#pipelinesObject (readonly)

Returns the value of attribute pipelines.



7
8
9
# File 'app/finders/ci/pipelines_finder.rb', line 7

def pipelines
  @pipelines
end

#projectObject (readonly)

Returns the value of attribute project.



7
8
9
# File 'app/finders/ci/pipelines_finder.rb', line 7

def project
  @project
end

Instance Method Details

#executeObject



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

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)
  items = by_name(items)

  sort_items(items)
end