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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-08 15:09:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-08 15:09:20 +0300
commit9e74a704bc63dc1e75cc8be67b7e0a1741e6696f (patch)
tree9e43f299bf242a80df5c26488cd177197ffbce3f /app/finders
parent1c6e8c149861e1027da40622536b5276c46a7408 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
-rw-r--r--app/finders/deployments_finder.rb74
1 files changed, 50 insertions, 24 deletions
diff --git a/app/finders/deployments_finder.rb b/app/finders/deployments_finder.rb
index 4038f93cf2d..bdcf7da3bea 100644
--- a/app/finders/deployments_finder.rb
+++ b/app/finders/deployments_finder.rb
@@ -1,16 +1,26 @@
# frozen_string_literal: true
+# Arguments:
+# params:
+# project: Project model - Find deployments for this project
+# updated_after: DateTime
+# updated_before: DateTime
+# finished_after: DateTime
+# finished_before: DateTime
+# environment: String
+# status: String (see Deployment.statuses)
+# order_by: String (see ALLOWED_SORT_VALUES constant)
+# sort: String (asc | desc)
class DeploymentsFinder
- attr_reader :project, :params
+ attr_reader :params
- ALLOWED_SORT_VALUES = %w[id iid created_at updated_at ref].freeze
+ ALLOWED_SORT_VALUES = %w[id iid created_at updated_at ref finished_at].freeze
DEFAULT_SORT_VALUE = 'id'
ALLOWED_SORT_DIRECTIONS = %w[asc desc].freeze
DEFAULT_SORT_DIRECTION = 'asc'
- def initialize(project, params = {})
- @project = project
+ def initialize(params = {})
@params = params
end
@@ -19,33 +29,20 @@ class DeploymentsFinder
items = by_updated_at(items)
items = by_environment(items)
items = by_status(items)
+ items = preload_associations(items)
+ items = by_finished_between(items)
sort(items)
end
private
- # rubocop: disable CodeReuse/ActiveRecord
def init_collection
- project
- .deployments
- .includes(
- :user,
- environment: [],
- deployable: {
- job_artifacts: [],
- pipeline: {
- project: {
- route: [],
- namespace: :route
- }
- },
- project: {
- namespace: :route
- }
- }
- )
+ if params[:project]
+ params[:project].deployments
+ else
+ Deployment.none
+ end
end
- # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def sort(items)
@@ -68,6 +65,12 @@ class DeploymentsFinder
end
end
+ def by_finished_between(items)
+ items = items.finished_between(params[:finished_after], params[:finished_before].presence) if params[:finished_after].present?
+
+ items
+ end
+
def by_status(items)
return items unless params[:status].present?
@@ -87,4 +90,27 @@ class DeploymentsFinder
sort_values['id'] = sort_values.delete('created_at') if sort_values['created_at'] # Sorting by `id` produces the same result as sorting by `created_at`
end
end
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ def preload_associations(scope)
+ scope.includes(
+ :user,
+ environment: [],
+ deployable: {
+ job_artifacts: [],
+ pipeline: {
+ project: {
+ route: [],
+ namespace: :route
+ }
+ },
+ project: {
+ namespace: :route
+ }
+ }
+ )
+ end
+ # rubocop: enable CodeReuse/ActiveRecord
end
+
+DeploymentsFinder.prepend_if_ee('EE::DeploymentsFinder')