Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
8a2bc9b4
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8a2bc9b4
编写于
3月 23, 2018
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Integration variables collections with expressions
上级
96d6193c
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
71 addition
and
45 deletion
+71
-45
lib/gitlab/ci/build/policy/variables.rb
lib/gitlab/ci/build/policy/variables.rb
+5
-1
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
+1
-1
lib/gitlab/ci/pipeline/expression/statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+2
-17
lib/gitlab/ci/variables/collection.rb
lib/gitlab/ci/variables/collection.rb
+7
-1
lib/gitlab/ci/variables/collection/item.rb
lib/gitlab/ci/variables/collection/item.rb
+2
-2
spec/lib/gitlab/ci/build/policy/variables_spec.rb
spec/lib/gitlab/ci/build/policy/variables_spec.rb
+25
-9
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+6
-10
spec/lib/gitlab/ci/variables/collection/item_spec.rb
spec/lib/gitlab/ci/variables/collection/item_spec.rb
+7
-3
spec/lib/gitlab/ci/variables/collection_spec.rb
spec/lib/gitlab/ci/variables/collection_spec.rb
+16
-1
未找到文件。
lib/gitlab/ci/build/policy/variables.rb
浏览文件 @
8a2bc9b4
...
...
@@ -8,9 +8,13 @@ module Gitlab
end
def
satisfied_by?
(
pipeline
,
build
)
variables
=
Gitlab
::
Ci
::
Variables
::
Collection
.
new
(
build
.
simple_variables
)
.
to_hash
statements
=
@expressions
.
map
do
|
statement
|
::
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Statement
.
new
(
statement
,
pipeline
)
.
new
(
statement
,
variables
)
end
statements
.
any?
(
&
:truthful?
)
...
...
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
浏览文件 @
8a2bc9b4
...
...
@@ -11,7 +11,7 @@ module Gitlab
end
def
evaluate
(
variables
=
{})
HashWithIndifferentAccess
.
new
(
variables
)
.
fetch
(
@name
,
nil
)
variables
.
with_indifferent_access
.
fetch
(
@name
,
nil
)
end
def
self
.
build
(
string
)
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
浏览文件 @
8a2bc9b4
...
...
@@ -14,24 +14,9 @@ module Gitlab
%w[variable]
].
freeze
def
initialize
(
statement
,
pipeline
=
nil
)
def
initialize
(
statement
,
variables
=
{}
)
@lexer
=
Expression
::
Lexer
.
new
(
statement
)
return
if
pipeline
.
nil?
# REFACTORING, temporary refactoring stubs
#
@variables
=
pipeline
.
project
.
predefined_variables
.
map
do
|
variable
|
[
variable
[
:key
],
variable
[
:value
]]
end
@variables
+=
pipeline
.
variables
.
map
do
|
variable
|
[
variable
.
key
,
variable
.
value
]
end
@variables
+=
pipeline
.
predefined_variables
.
map
do
|
variable
|
[
variable
[
:key
],
variable
[
:value
]]
end
@variables
=
variables
.
with_indifferent_access
end
def
parse_tree
...
...
lib/gitlab/ci/variables/collection.rb
浏览文件 @
8a2bc9b4
...
...
@@ -30,7 +30,13 @@ module Gitlab
end
def
to_runner_variables
self
.
map
(
&
:to_hash
)
self
.
map
(
&
:to_runner_variable
)
end
def
to_hash
self
.
to_runner_variables
.
map
{
|
env
|
[
env
.
fetch
(
:key
),
env
.
fetch
(
:value
)]
}
.
to_h
.
with_indifferent_access
end
end
end
...
...
lib/gitlab/ci/variables/collection/item.rb
浏览文件 @
8a2bc9b4
...
...
@@ -17,7 +17,7 @@ module Gitlab
end
def
==
(
other
)
to_
hash
==
self
.
class
.
fabricate
(
other
).
to_hash
to_
runner_variable
==
self
.
class
.
fabricate
(
other
).
to_runner_variable
end
##
...
...
@@ -25,7 +25,7 @@ module Gitlab
# don't expose `file` attribute at all (stems from what the runner
# expects).
#
def
to_
hash
def
to_
runner_variable
@variable
.
reject
do
|
hash_key
,
hash_value
|
hash_key
==
:file
&&
hash_value
==
false
end
...
...
spec/lib/gitlab/ci/build/policy/variables_spec.rb
浏览文件 @
8a2bc9b4
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Policy
::
Variables
do
let
(
:pipeline
)
{
build_stubbed
(
:ci_empty_pipeline
,
ref:
'master'
)
}
let
(
:build
)
{
build_stubbed
(
:ci_build
,
pipeline:
pipeline
,
ref:
'master'
)
}
set
(
:project
)
{
create
(
:project
)
}
let
(
:ci_pipeline
)
do
build
(
:ci_empty_pipeline
,
project:
project
,
ref:
'master'
)
end
let
(
:ci_build
)
do
build
(
:ci_build
,
pipeline:
ci_pipeline
,
project:
project
,
ref:
'master'
)
end
before
do
pipeline
.
variables
.
build
(
key:
'CI_PROJECT_NAME'
,
value:
''
)
ci_
pipeline
.
variables
.
build
(
key:
'CI_PROJECT_NAME'
,
value:
''
)
end
describe
'#satisfied_by?'
do
it
'is satisfied by a defined and existing variable'
do
policy
=
described_class
.
new
([
'$CI_PROJECT_ID'
,
'$UNDEFINED'
])
expect
(
policy
).
to
be_satisfied_by
(
pipeline
,
build
)
expect
(
policy
).
to
be_satisfied_by
(
ci_pipeline
,
ci_
build
)
end
it
'is not satisfied by an overriden empty variable'
do
policy
=
described_class
.
new
([
'$CI_PROJECT_NAME'
])
expect
(
policy
).
not_to
be_satisfied_by
(
pipeline
,
build
)
expect
(
policy
).
not_to
be_satisfied_by
(
ci_pipeline
,
ci_
build
)
end
it
'is satisfied by a truthy pipeline expression'
do
policy
=
described_class
.
new
([
%($CI_PIPELINE_SOURCE == "#{pipeline.source}")
])
policy
=
described_class
.
new
([
%($CI_PIPELINE_SOURCE == "#{
ci_
pipeline.source}")
])
expect
(
policy
).
to
be_satisfied_by
(
pipeline
,
build
)
expect
(
policy
).
to
be_satisfied_by
(
ci_pipeline
,
ci_
build
)
end
it
'is not satisfied by a falsy pipeline expression'
do
policy
=
described_class
.
new
([
%($CI_PIPELINE_SOURCE == "invalid source")
])
expect
(
policy
).
not_to
be_satisfied_by
(
pipeline
,
build
)
expect
(
policy
).
not_to
be_satisfied_by
(
ci_pipeline
,
ci_
build
)
end
it
'is satisfied by a truthy expression using undefined variable'
do
policy
=
described_class
.
new
([
'$UNDEFINED'
,
'$UNDEFINED == null'
])
expect
(
policy
).
to
be_satisfied_by
(
pipeline
,
build
)
expect
(
policy
).
to
be_satisfied_by
(
ci_pipeline
,
ci_
build
)
end
it
'does not persist neither pipeline nor build'
do
described_class
.
new
(
'$VAR'
).
satisfied_by?
(
ci_pipeline
,
ci_build
)
expect
(
ci_pipeline
).
not_to
be_persisted
expect
(
ci_build
).
not_to
be_persisted
end
pending
'test for secret variables'
end
end
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
浏览文件 @
8a2bc9b4
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Statement
do
let
(
:pipeline
)
{
build
(
:ci_pipeline
)
}
subject
do
described_class
.
new
(
text
,
pipeline
)
described_class
.
new
(
text
,
variables
)
end
before
do
variables
=
[{
key:
'PRESENT_VARIABLE'
,
value:
'my variable'
},
{
key:
'EMPTY_VARIABLE'
,
value:
''
}]
pipeline
.
variables
.
build
(
variables
)
let
(
:variables
)
do
{
'PRESENT_VARIABLE'
=>
'my variable'
,
EMPTY_VARIABLE
:
''
}
end
describe
'.new'
do
context
'when
pipeline is
not provided'
do
it
'allows to properly initialize the statement'
do
context
'when
variables are
not provided'
do
it
'allows to properly initialize
s
the statement'
do
statement
=
described_class
.
new
(
'$PRESENT_VARIABLE'
)
expect
(
statement
.
evaluate
).
to
be_nil
...
...
spec/lib/gitlab/ci/variables/collection/item_spec.rb
浏览文件 @
8a2bc9b4
...
...
@@ -46,9 +46,13 @@ describe Gitlab::Ci::Variables::Collection::Item do
end
end
describe
'#to_hash'
do
it
'returns a hash representation of a collection item'
do
expect
(
described_class
.
new
(
**
variable
).
to_hash
).
to
eq
variable
describe
'#to_runner_variable'
do
it
'returns a runner-compatible hash representation'
do
runner_variable
=
described_class
.
new
(
**
variable
)
.
to_runner_variable
expect
(
runner_variable
).
to
eq
variable
end
end
end
spec/lib/gitlab/ci/variables/collection_spec.rb
浏览文件 @
8a2bc9b4
...
...
@@ -7,7 +7,7 @@ describe Gitlab::Ci::Variables::Collection do
collection
=
described_class
.
new
([
variable
])
expect
(
collection
.
first
.
to_
hash
).
to
eq
variable
expect
(
collection
.
first
.
to_
runner_variable
).
to
eq
variable
end
it
'can be initialized without an argument'
do
...
...
@@ -96,4 +96,19 @@ describe Gitlab::Ci::Variables::Collection do
.
to
eq
[{
key:
'TEST'
,
value:
1
,
public:
true
}]
end
end
describe
'#to_hash'
do
it
'returns regular hash in valid order without duplicates'
do
collection
=
described_class
.
new
.
append
(
key:
'TEST1'
,
value:
'test-1'
)
.
append
(
key:
'TEST2'
,
value:
'test-2'
)
.
append
(
key:
'TEST1'
,
value:
'test-3'
)
expect
(
collection
.
to_hash
).
to
eq
(
'TEST1'
=>
'test-3'
,
'TEST2'
=>
'test-2'
)
expect
(
collection
.
to_hash
).
to
include
(
TEST1
:
'test-3'
)
expect
(
collection
.
to_hash
).
not_to
include
(
TEST1
:
'test-1'
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录