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
65f4e7b2
Commit
65f4e7b2
authored
May 15, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for pattern matching in variables expressions
parent
475d2edf
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
27 additions
and
7 deletions
+27
-7
lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
+1
-1
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
+2
-0
lib/gitlab/ci/pipeline/expression/lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+3
-1
lib/gitlab/ci/pipeline/expression/statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+3
-1
spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
.../lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
+10
-0
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
.../lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
+0
-1
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+8
-3
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
View file @
65f4e7b2
...
...
@@ -15,7 +15,7 @@ module Gitlab
text
=
@left
.
evaluate
(
variables
)
regexp
=
@right
.
evaluate
(
variables
)
regexp
.
scan
(
text
).
any?
regexp
.
scan
(
text
.
to_s
).
any?
end
def
self
.
build
(
_value
,
behind
,
ahead
)
...
...
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
View file @
65f4e7b2
...
...
@@ -3,6 +3,8 @@ module Gitlab
module
Pipeline
module
Expression
module
Lexeme
require_dependency
're2'
class
Pattern
<
Lexeme
::
Value
PATTERN
=
%r{/(?<regexp>.+)/}
.
freeze
...
...
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
65f4e7b2
...
...
@@ -10,8 +10,10 @@ module Gitlab
LEXEMES
=
[
Expression
::
Lexeme
::
Variable
,
Expression
::
Lexeme
::
String
,
Expression
::
Lexeme
::
Pattern
,
Expression
::
Lexeme
::
Null
,
Expression
::
Lexeme
::
Equals
Expression
::
Lexeme
::
Equals
,
Expression
::
Lexeme
::
Matches
].
freeze
MAX_TOKENS
=
100
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
View file @
65f4e7b2
...
...
@@ -6,12 +6,14 @@ module Gitlab
StatementError
=
Class
.
new
(
Expression
::
ExpressionError
)
GRAMMAR
=
[
%w[variable]
,
%w[variable equals string]
,
%w[variable equals variable]
,
%w[variable equals null]
,
%w[string equals variable]
,
%w[null equals variable]
,
%w[variable]
%w[variable matches pattern]
,
%w[pattern matches variable]
].
freeze
def
initialize
(
statement
,
variables
=
{})
...
...
spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
View file @
65f4e7b2
...
...
@@ -39,6 +39,16 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do
expect
(
operator
.
evaluate
).
to
eq
true
end
it
'supports matching against a nil value'
do
allow
(
left
).
to
receive
(
:evaluate
).
and_return
(
nil
)
allow
(
right
).
to
receive
(
:evaluate
)
.
and_return
(
Gitlab
::
UntrustedRegexp
.
new
(
'pattern'
))
operator
=
described_class
.
new
(
left
,
right
)
expect
(
operator
.
evaluate
).
to
eq
false
end
it
'supports multiline strings'
do
allow
(
left
).
to
receive
(
:evaluate
).
and_return
<<~
TEXT
My awesome contents
...
...
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
View file @
65f4e7b2
require
'fast_spec_helper'
require_dependency
're2'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Pattern
do
describe
'.build'
do
...
...
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
View file @
65f4e7b2
...
...
@@ -84,7 +84,6 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
describe
'#evaluate'
do
statements
=
[
[
'$PRESENT_VARIABLE == "my variable"'
,
true
],
[
"$PRESENT_VARIABLE == 'my variable'"
,
true
],
[
'"my variable" == $PRESENT_VARIABLE'
,
true
],
[
'$PRESENT_VARIABLE == null'
,
false
],
[
'$EMPTY_VARIABLE == null'
,
false
],
...
...
@@ -93,7 +92,11 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
[
'$UNDEFINED_VARIABLE == null'
,
true
],
[
'null == $UNDEFINED_VARIABLE'
,
true
],
[
'$PRESENT_VARIABLE'
,
'my variable'
],
[
'$UNDEFINED_VARIABLE'
,
nil
]
[
'$UNDEFINED_VARIABLE'
,
nil
],
[
"$PRESENT_VARIABLE =~ /var.*e$/"
,
true
],
[
"$PRESENT_VARIABLE =~ /^var.*/"
,
false
],
[
"$EMPTY_VARIABLE =~ /var.*/"
,
false
],
[
"$UNDEFINED_VARIABLE =~ /var.*/"
,
false
]
]
statements
.
each
do
|
expression
,
value
|
...
...
@@ -115,7 +118,9 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
[
'$PRESENT_VARIABLE'
,
true
],
[
'$UNDEFINED_VARIABLE'
,
false
],
[
'$EMPTY_VARIABLE'
,
false
],
[
'$INVALID = 1'
,
false
]
[
'$INVALID = 1'
,
false
],
[
"$PRESENT_VARIABLE =~ /var.*/"
,
true
],
[
"$UNDEFINED_VARIABLE =~ /var.*/"
,
false
]
]
statements
.
each
do
|
expression
,
value
|
...
...
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