diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-02-05 16:14:30 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-02-06 18:14:18 +0900 |
commit | e8d9df83a6f5638b3207885220b9441b7b894e46 (patch) | |
tree | d28aa89c50dd1916721d2aad562fb95249d40f75 /app/models/environment.rb | |
parent | 591380a3f1bf1b5220f176f082af297831a1886e (diff) | |
download | gitlab-ce-e8d9df83a6f5638b3207885220b9441b7b894e46.tar.gz |
Inroduce Internal API for searching environment namesintroduce-environment-search-endpoint
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.rb | 12 |
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) |