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
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
end
def
evaluate
(
variables
=
{})
# TODO multiline support
@regexp
=
Gitlab
::
UntrustedRegexp
.
new
(
@value
)
rescue
RegexpError
raise
Parser
::
Parser
Error
,
'Invalid regular expression!'
raise
Expression
::
Runtime
Error
,
'Invalid regular expression!'
end
def
self
.
build
(
string
)
...
...
lib/gitlab/ci/pipeline/expression/lexer.rb
View file @
475d2edf
...
...
@@ -5,6 +5,8 @@ module Gitlab
class
Lexer
include
::
Gitlab
::
Utils
::
StrongMemoize
SyntaxError
=
Class
.
new
(
Expression
::
ExpressionError
)
LEXEMES
=
[
Expression
::
Lexeme
::
Variable
,
Expression
::
Lexeme
::
String
,
...
...
@@ -12,8 +14,6 @@ module Gitlab
Expression
::
Lexeme
::
Equals
].
freeze
SyntaxError
=
Class
.
new
(
Statement
::
StatementError
)
MAX_TOKENS
=
100
def
initialize
(
statement
,
max_tokens:
MAX_TOKENS
)
...
...
lib/gitlab/ci/pipeline/expression/parser.rb
View file @
475d2edf
...
...
@@ -3,8 +3,6 @@ module Gitlab
module
Pipeline
module
Expression
class
Parser
ParserError
=
Class
.
new
(
Statement
::
StatementError
)
def
initialize
(
tokens
)
@tokens
=
tokens
.
to_enum
@nodes
=
[]
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
View file @
475d2edf
...
...
@@ -3,7 +3,7 @@ module Gitlab
module
Pipeline
module
Expression
class
Statement
StatementError
=
Class
.
new
(
Standard
Error
)
StatementError
=
Class
.
new
(
Expression
::
Expression
Error
)
GRAMMAR
=
[
%w[variable equals string]
,
...
...
@@ -35,13 +35,13 @@ module Gitlab
def
truthful?
evaluate
.
present?
rescue
Statement
Error
rescue
Expression
::
Expression
Error
false
end
def
valid?
parse_tree
.
is_a?
(
Lexeme
::
Base
)
rescue
Statement
Error
rescue
Expression
::
Expression
Error
false
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
regexp
=
described_class
.
new
(
'invalid ( .*'
)
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
spec/lib/gitlab/ci/pipeline/expression/lexer_spec.rb
View file @
475d2edf
...
...
@@ -6,7 +6,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
end
describe
'#tokens'
do
it
'
tokens
s single value'
do
it
'
return
s single value'
do
tokens
=
described_class
.
new
(
'$VARIABLE'
).
tokens
expect
(
tokens
).
to
be_one
...
...
@@ -20,14 +20,14 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
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
expect
(
tokens
.
size
).
to
eq
2
expect
(
tokens
).
to
all
(
be_an_instance_of
(
token_class
))
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
expect
(
tokens
.
size
).
to
eq
3
...
...
@@ -36,7 +36,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexer do
expect
(
tokens
.
third
.
value
).
to
eq
'"value"'
end
it
'
tokens
s tokens and operators'
do
it
'
return
s tokens and operators'
do
tokens
=
described_class
.
new
(
'$VARIABLE == "text"'
).
tokens
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
'== "123"'
,
# invalid left side
'"some string"'
,
# only string provided
'$VAR =='
,
# invalid right side
'
12345'
,
# unknown syntax
'
null'
,
# missing lexemes
''
# empty statement
]
...
...
@@ -44,7 +44,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
context
"when expression grammar is
#{
syntax
.
inspect
}
"
do
let
(
:text
)
{
syntax
}
it
'aises a statement error exception'
do
it
'
r
aises a statement error exception'
do
expect
{
subject
.
parse_tree
}
.
to
raise_error
described_class
::
StatementError
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