Commit 3230030d authored by Stan Hu's avatar Stan Hu

Merge branch 'dz-refactor-environments-finder-2' into 'master'

Rename find to execute in EnvironmentsFinder

See merge request gitlab-org/gitlab!59254
parents a4b4d9f2 2f536c6f
...@@ -58,7 +58,7 @@ module Projects ...@@ -58,7 +58,7 @@ module Projects
def environment def environment
strong_memoize(:environment) do strong_memoize(:environment) do
if cluster_params.key?(:environment_name) if cluster_params.key?(:environment_name)
EnvironmentsFinder.new(project, current_user, name: cluster_params[:environment_name]).find.first EnvironmentsFinder.new(project, current_user, name: cluster_params[:environment_name]).execute.first
else else
project.default_environment project.default_environment
end end
......
...@@ -9,12 +9,7 @@ class EnvironmentsFinder ...@@ -9,12 +9,7 @@ class EnvironmentsFinder
@project, @current_user, @params = project, current_user, params @project, @current_user, @params = project, current_user, params
end end
# This method will eventually take the place of `#execute` as an def execute
# efficient way to get relevant environment entries.
# Currently, `#execute` method has a serious technical debt and
# we will likely rework on it in the future.
# See more https://gitlab.com/gitlab-org/gitlab-foss/issues/63381
def find
environments = project.environments environments = project.environments
environments = by_name(environments) environments = by_name(environments)
environments = by_search(environments) environments = by_search(environments)
......
...@@ -21,7 +21,7 @@ module Resolvers ...@@ -21,7 +21,7 @@ module Resolvers
def resolve(**args) def resolve(**args)
return unless project.present? return unless project.present?
EnvironmentsFinder.new(project, context[:current_user], args).find EnvironmentsFinder.new(project, context[:current_user], args).execute
rescue EnvironmentsFinder::InvalidStatesError => exception rescue EnvironmentsFinder::InvalidStatesError => exception
raise Gitlab::Graphql::Errors::ArgumentError, exception.message raise Gitlab::Graphql::Errors::ArgumentError, exception.message
end end
......
...@@ -84,7 +84,7 @@ module Prometheus ...@@ -84,7 +84,7 @@ module Prometheus
def environment def environment
strong_memoize(:environment) do strong_memoize(:environment) do
EnvironmentsFinder.new(project, nil, name: 'production').find.first || EnvironmentsFinder.new(project, nil, name: 'production').execute.first ||
project.environments.first project.environments.first
end end
end end
......
...@@ -26,7 +26,7 @@ module API ...@@ -26,7 +26,7 @@ module API
get ':id/environments' do get ':id/environments' do
authorize! :read_environment, user_project authorize! :read_environment, user_project
environments = ::EnvironmentsFinder.new(user_project, current_user, params).find environments = ::EnvironmentsFinder.new(user_project, current_user, params).execute
present paginate(environments), with: Entities::Environment, current_user: current_user present paginate(environments), with: Entities::Environment, current_user: current_user
end end
......
...@@ -132,7 +132,7 @@ module Gitlab ...@@ -132,7 +132,7 @@ module Gitlab
EnvironmentsFinder EnvironmentsFinder
.new(project, nil, { name: environment_name }) .new(project, nil, { name: environment_name })
.find .execute
.first .first
end end
end end
......
...@@ -11,37 +11,37 @@ RSpec.describe EnvironmentsFinder do ...@@ -11,37 +11,37 @@ RSpec.describe EnvironmentsFinder do
project.add_maintainer(user) project.add_maintainer(user)
end end
describe '#find' do describe '#execute' do
context 'with states parameter' do context 'with states parameter' do
let(:stopped_environment) { create(:environment, :stopped, project: project) } let(:stopped_environment) { create(:environment, :stopped, project: project) }
it 'returns environments with the requested state' do it 'returns environments with the requested state' do
result = described_class.new(project, user, states: 'available').find result = described_class.new(project, user, states: 'available').execute
expect(result).to contain_exactly(environment) expect(result).to contain_exactly(environment)
end end
it 'returns environments with any of the requested states' do it 'returns environments with any of the requested states' do
result = described_class.new(project, user, states: %w(available stopped)).find result = described_class.new(project, user, states: %w(available stopped)).execute
expect(result).to contain_exactly(environment, stopped_environment) expect(result).to contain_exactly(environment, stopped_environment)
end end
it 'raises exception when requested state is invalid' do it 'raises exception when requested state is invalid' do
expect { described_class.new(project, user, states: %w(invalid stopped)).find }.to( expect { described_class.new(project, user, states: %w(invalid stopped)).execute }.to(
raise_error(described_class::InvalidStatesError, 'Requested states are invalid') raise_error(described_class::InvalidStatesError, 'Requested states are invalid')
) )
end end
context 'works with symbols' do context 'works with symbols' do
it 'returns environments with the requested state' do it 'returns environments with the requested state' do
result = described_class.new(project, user, states: :available).find result = described_class.new(project, user, states: :available).execute
expect(result).to contain_exactly(environment) expect(result).to contain_exactly(environment)
end end
it 'returns environments with any of the requested states' do it 'returns environments with any of the requested states' do
result = described_class.new(project, user, states: [:available, :stopped]).find result = described_class.new(project, user, states: [:available, :stopped]).execute
expect(result).to contain_exactly(environment, stopped_environment) expect(result).to contain_exactly(environment, stopped_environment)
end end
...@@ -53,7 +53,7 @@ RSpec.describe EnvironmentsFinder do ...@@ -53,7 +53,7 @@ RSpec.describe EnvironmentsFinder do
let(:environment3) { create(:environment, :available, name: 'test3', project: project) } let(:environment3) { create(:environment, :available, name: 'test3', project: project) }
it 'searches environments by name and state' do it 'searches environments by name and state' do
result = described_class.new(project, user, search: 'test', states: :available).find result = described_class.new(project, user, search: 'test', states: :available).execute
expect(result).to contain_exactly(environment3) expect(result).to contain_exactly(environment3)
end end
......
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