Commit e3f7cdda authored by Vitali Tatarintev's avatar Vitali Tatarintev

Move Project.environments_for_scope to CE

Contributes to migration of Prometheus alerts to Core
parent 59b731a5
......@@ -2416,6 +2416,12 @@ class Project < ApplicationRecord
branch_protection.fully_protected? || branch_protection.developer_can_merge?
end
def environments_for_scope(scope)
quoted_scope = ::Gitlab::SQL::Glob.q(scope)
environments.where("name LIKE (#{::Gitlab::SQL::Glob.to_like(quoted_scope)})") # rubocop:disable GitlabSecurity/SqlInjection
end
private
def closest_namespace_setting(name)
......
......@@ -222,12 +222,6 @@ module EE
all_pipelines.newest_first(ref: default_branch).with_reports(reports).take
end
def environments_for_scope(scope)
quoted_scope = ::Gitlab::SQL::Glob.q(scope)
environments.where("name LIKE (#{::Gitlab::SQL::Glob.to_like(quoted_scope)})") # rubocop:disable GitlabSecurity/SqlInjection
end
def ensure_external_webhook_token
return if external_webhook_token.present?
......
......@@ -433,24 +433,6 @@ describe Project do
end
end
describe '#environments_for_scope' do
let_it_be(:project, reload: true) { create(:project) }
before do
create_list(:environment, 2, project: project)
end
it 'retrieves all project environments when using the * wildcard' do
expect(project.environments_for_scope("*")).to eq(project.environments)
end
it 'retrieves a specific project environment when using the name of that environment' do
environment = project.environments.first
expect(project.environments_for_scope(environment.name)).to eq([environment])
end
end
describe '#ensure_external_webhook_token' do
let(:project) { create(:project, :repository) }
......
......@@ -5935,6 +5935,24 @@ describe Project do
end
end
describe '#environments_for_scope' do
let_it_be(:project, reload: true) { create(:project) }
before do
create_list(:environment, 2, project: project)
end
it 'retrieves all project environments when using the * wildcard' do
expect(project.environments_for_scope("*")).to eq(project.environments)
end
it 'retrieves a specific project environment when using the name of that environment' do
environment = project.environments.first
expect(project.environments_for_scope(environment.name)).to eq([environment])
end
end
def finish_job(export_job)
export_job.start
export_job.finish
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment