Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fa29f79a
Commit
fa29f79a
authored
Nov 30, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Centerlize process of filitering by environment_scope between ci_variables and clusters
parent
40c2617d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
51 deletions
+55
-51
ee/app/models/ci/has_environment_scope.rb
ee/app/models/ci/has_environment_scope.rb
+51
-0
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+4
-51
No files found.
ee/app/models/ci/has_environment_scope.rb
View file @
fa29f79a
...
...
@@ -2,6 +2,57 @@ module Ci
module
HasEnvironmentScope
extend
ActiveSupport
::
Concern
class
<<
self
def
filter_by_environment_scope
(
base_query
,
environment_name
)
where
=
<<~
SQL
environment_scope IN (:wildcard, :environment_name) OR
:environment_name LIKE
#{
::
Gitlab
::
SQL
::
Glob
.
to_like
(
'environment_scope'
)
}
SQL
order
=
<<~
SQL
CASE environment_scope
WHEN %{wildcard} THEN 0
WHEN %{environment_name} THEN 2
ELSE 1
END
SQL
values
=
{
wildcard:
'*'
,
environment_name:
environment_name
}
quoted_values
=
values
.
transform_values
do
|
value
|
# Note that the connection could be
# Gitlab::Database::LoadBalancing::ConnectionProxy
# which supports `quote` via `method_missing`
self
.
class
.
connection
.
quote
(
value
)
end
# The query is trying to find variables with scopes matching the
# current environment name. Suppose the environment name is
# 'review/app', and we have variables with environment scopes like:
# * variable A: review
# * variable B: review/app
# * variable C: review/*
# * variable D: *
# And the query should find variable B, C, and D, because it would
# try to convert the scope into a LIKE pattern for each variable:
# * A: review
# * B: review/app
# * C: review/%
# * D: %
# Note that we'll match % and _ literally therefore we'll escape them.
# In this case, B, C, and D would match. We also want to prioritize
# the exact matched name, and put * last, and everything else in the
# middle. So the order should be: D < C < B
query
.
where
(
where
,
values
)
.
order
(
order
%
quoted_values
)
# `order` cannot escape for us!
end
end
prepended
do
validates
(
:environment_scope
,
...
...
ee/app/models/ee/project.rb
View file @
fa29f79a
...
...
@@ -257,9 +257,9 @@ module EE
def
deployment_platform
(
environment:
nil
)
return
super
unless
environment
&&
feature_available?
(
:multiple_clusters
)
@deployment_platform
||=
clusters
.
select
do
|
cluster
|
cluster
.
matches?
(
environment
)
# TODO: This is the same logic with Environment Variable
end
.
fir
st
&
.
platform_kubernetes
@deployment_platform
||=
Ci
::
HasEnvironmentScope
.
filter_by
(
clusters
.
enabled
,
environment
.
name
)
.
la
st
&
.
platform_kubernetes
super
# Wildcard or KubernetesService
end
...
...
@@ -268,54 +268,7 @@ module EE
return
super
.
where
(
environment_scope:
'*'
)
unless
environment
&&
feature_available?
(
:variable_environment_scope
)
query
=
super
where
=
<<~
SQL
environment_scope IN (:wildcard, :environment_name) OR
:environment_name LIKE
#{
::
Gitlab
::
SQL
::
Glob
.
to_like
(
'environment_scope'
)
}
SQL
order
=
<<~
SQL
CASE environment_scope
WHEN %{wildcard} THEN 0
WHEN %{environment_name} THEN 2
ELSE 1
END
SQL
values
=
{
wildcard:
'*'
,
environment_name:
environment
.
name
}
quoted_values
=
values
.
transform_values
do
|
value
|
# Note that the connection could be
# Gitlab::Database::LoadBalancing::ConnectionProxy
# which supports `quote` via `method_missing`
self
.
class
.
connection
.
quote
(
value
)
end
# The query is trying to find variables with scopes matching the
# current environment name. Suppose the environment name is
# 'review/app', and we have variables with environment scopes like:
# * variable A: review
# * variable B: review/app
# * variable C: review/*
# * variable D: *
# And the query should find variable B, C, and D, because it would
# try to convert the scope into a LIKE pattern for each variable:
# * A: review
# * B: review/app
# * C: review/%
# * D: %
# Note that we'll match % and _ literally therefore we'll escape them.
# In this case, B, C, and D would match. We also want to prioritize
# the exact matched name, and put * last, and everything else in the
# middle. So the order should be: D < C < B
query
.
where
(
where
,
values
)
.
order
(
order
%
quoted_values
)
# `order` cannot escape for us!
Ci
::
HasEnvironmentScope
.
filter_by
(
super
,
environment
.
name
)
end
def
execute_hooks
(
data
,
hooks_scope
=
:push_hooks
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment