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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
475d2edf
Commit
475d2edf
authored
May 15, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reorganize exceptions in pipeline expressions module
parent
bbba6d7e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
16 deletions
+23
-16
lib/gitlab/ci/pipeline/expression.rb
lib/gitlab/ci/pipeline/expression.rb
+10
-0
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
+1
-2
lib/gitlab/ci/pipeline/expression/lexer.rb
lib/gitlab/ci/pipeline/expression/lexer.rb
+2
-2
lib/gitlab/ci/pipeline/expression/parser.rb
lib/gitlab/ci/pipeline/expression/parser.rb
+0
-2
lib/gitlab/ci/pipeline/expression/statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+3
-3
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
.../lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
+1
-1
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
+4
-4
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+2
-2
No files found.
lib/gitlab/ci/pipeline/expression.rb
0 → 100644
View file @
475d2edf
module
Gitlab
module
Ci
module
Pipeline
module
Expression
ExpressionError
=
Class
.
new
(
StandardError
)
RuntimeError
=
Class
.
new
(
ExpressionError
)
end
end
end
end
lib/gitlab/ci/pipeline/expression/lexeme/pattern.rb
View file @
475d2edf
...
@@ -11,10 +11,9 @@ module Gitlab
...
@@ -11,10 +11,9 @@ module Gitlab
end
end
def
evaluate
(
variables
=
{})
def
evaluate
(
variables
=
{})
# TODO multiline support
@regexp
=
Gitlab
::
UntrustedRegexp
.
new
(
@value
)
@regexp
=
Gitlab
::
UntrustedRegexp
.
new
(
@value
)
rescue
RegexpError
rescue
RegexpError
raise
Parser
::
Parser
Error
,
'Invalid regular expression!'
raise
Expression
::
Runtime
Error
,
'Invalid regular expression!'
end
end
def
self
.
build
(
string
)
def
self
.
build
(
string
)
...
...
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
475d2edf
...
@@ -5,6 +5,8 @@ module Gitlab
...
@@ -5,6 +5,8 @@ module Gitlab
class
Lexer
class
Lexer
include
::
Gitlab
::
Utils
::
StrongMemoize
include
::
Gitlab
::
Utils
::
StrongMemoize
SyntaxError
=
Class
.
new
(
Expression
::
ExpressionError
)
LEXEMES
=
[
LEXEMES
=
[
Expression
::
Lexeme
::
Variable
,
Expression
::
Lexeme
::
Variable
,
Expression
::
Lexeme
::
String
,
Expression
::
Lexeme
::
String
,
...
@@ -12,8 +14,6 @@ module Gitlab
...
@@ -12,8 +14,6 @@ module Gitlab
Expression
::
Lexeme
::
Equals
Expression
::
Lexeme
::
Equals
].
freeze
].
freeze
SyntaxError
=
Class
.
new
(
Statement
::
StatementError
)
MAX_TOKENS
=
100
MAX_TOKENS
=
100
def
initialize
(
statement
,
max_tokens:
MAX_TOKENS
)
def
initialize
(
statement
,
max_tokens:
MAX_TOKENS
)
...
...
lib/gitlab/ci/pipeline/expression/parser.rb
View file @
475d2edf
...
@@ -3,8 +3,6 @@ module Gitlab
...
@@ -3,8 +3,6 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Expression
module
Expression
class
Parser
class
Parser
ParserError
=
Class
.
new
(
Statement
::
StatementError
)
def
initialize
(
tokens
)
def
initialize
(
tokens
)
@tokens
=
tokens
.
to_enum
@tokens
=
tokens
.
to_enum
@nodes
=
[]
@nodes
=
[]
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
View file @
475d2edf
...
@@ -3,7 +3,7 @@ module Gitlab
...
@@ -3,7 +3,7 @@ module Gitlab
module
Pipeline
module
Pipeline
module
Expression
module
Expression
class
Statement
class
Statement
StatementError
=
Class
.
new
(
Standard
Error
)
StatementError
=
Class
.
new
(
Expression
::
Expression
Error
)
GRAMMAR
=
[
GRAMMAR
=
[
%w[variable equals string]
,
%w[variable equals string]
,
...
@@ -35,13 +35,13 @@ module Gitlab
...
@@ -35,13 +35,13 @@ module Gitlab
def
truthful?
def
truthful?
evaluate
.
present?
evaluate
.
present?
rescue
Statement
Error
rescue
Expression
::
Expression
Error
false
false
end
end
def
valid?
def
valid?
parse_tree
.
is_a?
(
Lexeme
::
Base
)
parse_tree
.
is_a?
(
Lexeme
::
Base
)
rescue
Statement
Error
rescue
Expression
::
Expression
Error
false
false
end
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/expression/lexeme/pattern_spec.rb
View file @
475d2edf
...
@@ -56,7 +56,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern do
...
@@ -56,7 +56,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Pattern do
regexp
=
described_class
.
new
(
'invalid ( .*'
)
regexp
=
described_class
.
new
(
'invalid ( .*'
)
expect
{
regexp
.
evaluate
}
expect
{
regexp
.
evaluate
}
.
to
raise_error
(
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Parser
::
Parser
Error
)
.
to
raise_error
(
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Runtime
Error
)
end
end
end
end
end
end
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
View file @
475d2edf
...
@@ -6,7 +6,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
...
@@ -6,7 +6,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
end
end
describe
'#tokens'
do
describe
'#tokens'
do
it
'
tokens
s single value'
do
it
'
return
s single value'
do
tokens
=
described_class
.
new
(
'$VARIABLE'
).
tokens
tokens
=
described_class
.
new
(
'$VARIABLE'
).
tokens
expect
(
tokens
).
to
be_one
expect
(
tokens
).
to
be_one
...
@@ -20,14 +20,14 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
...
@@ -20,14 +20,14 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
end
end
it
'
tokens
s multiple values of the same token'
do
it
'
return
s multiple values of the same token'
do
tokens
=
described_class
.
new
(
"$VARIABLE1 $VARIABLE2"
).
tokens
tokens
=
described_class
.
new
(
"$VARIABLE1 $VARIABLE2"
).
tokens
expect
(
tokens
.
size
).
to
eq
2
expect
(
tokens
.
size
).
to
eq
2
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
end
end
it
'
tokens
s multiple values with different tokens'
do
it
'
return
s multiple values with different tokens'
do
tokens
=
described_class
.
new
(
'$VARIABLE "text" "value"'
).
tokens
tokens
=
described_class
.
new
(
'$VARIABLE "text" "value"'
).
tokens
expect
(
tokens
.
size
).
to
eq
3
expect
(
tokens
.
size
).
to
eq
3
...
@@ -36,7 +36,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
...
@@ -36,7 +36,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
expect
(
tokens
.
third
.
value
).
to
eq
'"value"'
expect
(
tokens
.
third
.
value
).
to
eq
'"value"'
end
end
it
'
tokens
s tokens and operators'
do
it
'
return
s tokens and operators'
do
tokens
=
described_class
.
new
(
'$VARIABLE == "text"'
).
tokens
tokens
=
described_class
.
new
(
'$VARIABLE == "text"'
).
tokens
expect
(
tokens
.
size
).
to
eq
3
expect
(
tokens
.
size
).
to
eq
3
...
...
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
View file @
475d2edf
...
@@ -36,7 +36,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
...
@@ -36,7 +36,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
'== "123"'
,
# invalid left side
'== "123"'
,
# invalid left side
'"some string"'
,
# only string provided
'"some string"'
,
# only string provided
'$VAR =='
,
# invalid right side
'$VAR =='
,
# invalid right side
'
12345'
,
# unknown syntax
'
null'
,
# missing lexemes
''
# empty statement
''
# empty statement
]
]
...
@@ -44,7 +44,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
...
@@ -44,7 +44,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
context
"when expression grammar is
#{
syntax
.
inspect
}
"
do
context
"when expression grammar is
#{
syntax
.
inspect
}
"
do
let
(
:text
)
{
syntax
}
let
(
:text
)
{
syntax
}
it
'aises a statement error exception'
do
it
'
r
aises a statement error exception'
do
expect
{
subject
.
parse_tree
}
expect
{
subject
.
parse_tree
}
.
to
raise_error
described_class
::
StatementError
.
to
raise_error
described_class
::
StatementError
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