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:
authorShinya Maeda <shinya@gitlab.com>2019-02-05 10:14:30 +0300
committerShinya Maeda <shinya@gitlab.com>2019-02-06 12:14:18 +0300
commite8d9df83a6f5638b3207885220b9441b7b894e46 (patch)
treed28aa89c50dd1916721d2aad562fb95249d40f75 /app/models/environment.rb
parent591380a3f1bf1b5220f176f082af297831a1886e (diff)
Inroduce Internal API for searching environment names
Add changelog Rename word to query User hash for limit Do not allow control limit Rename pluck names and add more specs
Diffstat (limited to 'app/models/environment.rb')
-rw-r--r--app/models/environment.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb
index cdfe3b7c023..1fc088b12ae 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -50,6 +50,14 @@ class Environment < ActiveRecord::Base
end
scope :in_review_folder, -> { where(environment_type: "review") }
scope :for_name, -> (name) { where(name: name) }
+
+ ##
+ # Search environments which have names like the given query.
+ # Do not set a large limit unless you've confirmed that it works on gitlab.com scale.
+ scope :for_name_like, -> (query, limit: 5) do
+ where('name LIKE ?', "#{sanitize_sql_like(query)}%").limit(limit)
+ end
+
scope :for_project, -> (project) { where(project_id: project) }
scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) }
@@ -70,6 +78,10 @@ class Environment < ActiveRecord::Base
end
end
+ def self.pluck_names
+ pluck(:name)
+ end
+
def predefined_variables
Gitlab::Ci::Variables::Collection.new
.append(key: 'CI_ENVIRONMENT_NAME', value: name)