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
227e18ea
Commit
227e18ea
authored
Feb 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for evaluating pipeline expression variables
parent
8c7374ca
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
6 deletions
+32
-6
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
+1
-1
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
+5
-1
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
+1
-1
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
+2
-1
lib/gitlab/ci/pipeline/expression/lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+1
-0
lib/gitlab/ci/pipeline/expression/statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+2
-2
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+20
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
View file @
227e18ea
...
...
@@ -11,7 +11,7 @@ module Gitlab
@right
=
right
end
def
evaluate
(
**
variables
)
def
evaluate
(
variables
)
@left
.
evaluate
(
variables
)
==
@right
.
evaluate
(
variables
)
end
...
...
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
View file @
227e18ea
...
...
@@ -10,9 +10,13 @@ module Gitlab
@value
=
value
end
def
evaluate
(
**
_
)
def
evaluate
(
_
)
nil
end
def
self
.
build
(
value
)
new
(
value
)
end
end
end
end
...
...
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
View file @
227e18ea
...
...
@@ -10,7 +10,7 @@ module Gitlab
@value
=
value
end
def
evaluate
(
**
_
)
def
evaluate
(
_
)
@value
.
to_s
end
...
...
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
View file @
227e18ea
...
...
@@ -10,7 +10,8 @@ module Gitlab
@name
=
name
end
def
evaluate
(
**
variables
)
def
evaluate
(
variables
)
variables
[
@name
]
end
def
self
.
build
(
string
)
...
...
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
227e18ea
...
...
@@ -6,6 +6,7 @@ module Gitlab
LEXEMES
=
[
Expression
::
Lexeme
::
Variable
,
Expression
::
Lexeme
::
String
,
Expression
::
Lexeme
::
Null
,
Expression
::
Lexeme
::
Equals
].
freeze
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
View file @
227e18ea
...
...
@@ -18,7 +18,7 @@ module Gitlab
@lexer
=
Expression
::
Lexer
.
new
(
statement
)
@variables
=
pipeline
.
variables
.
map
do
|
variable
|
{
variable
.
key
=>
variable
.
value
}
[
variable
.
key
,
variable
.
value
]
end
end
...
...
@@ -33,7 +33,7 @@ module Gitlab
end
def
evaluate
parse_tree
.
evaluate
(
**
@variables
)
parse_tree
.
evaluate
(
@variables
.
to_h
)
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
View file @
227e18ea
...
...
@@ -60,4 +60,24 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
end
end
describe
'#evaluate'
do
statements
=
[
[
'$VARIABLE == "my variable"'
,
true
],
[
'"my variable" == $VARIABLE'
,
true
],
[
'$VARIABLE == null'
,
false
],
[
'$VAR == null'
,
true
],
[
'null == $VAR'
,
true
],
[
'$VARIABLE'
,
'my variable'
],
[
'$VAR'
,
nil
],
]
statements
.
each
do
|
expression
,
value
|
it
"evaluates `
#{
expression
}
` to `
#{
value
}
`"
do
statement
=
described_class
.
new
(
expression
,
pipeline
)
expect
(
statement
.
evaluate
).
to
eq
value
end
end
end
end
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