Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a7ac2f74
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,发现更多精彩内容 >>
提交
a7ac2f74
编写于
7月 07, 2016
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify CI config entry node factory, use attribs
上级
9410aecc
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
37 addition
and
54 deletion
+37
-54
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+3
-1
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+7
-7
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+9
-18
lib/gitlab/ci/config/node/global.rb
lib/gitlab/ci/config/node/global.rb
+4
-0
lib/gitlab/ci/config/node/jobs.rb
lib/gitlab/ci/config/node/jobs.rb
+5
-5
lib/gitlab/ci/config/node/undefined.rb
lib/gitlab/ci/config/node/undefined.rb
+2
-4
spec/lib/gitlab/ci/config/node/factory_spec.rb
spec/lib/gitlab/ci/config/node/factory_spec.rb
+7
-19
未找到文件。
lib/gitlab/ci/config/node/configurable.rb
浏览文件 @
a7ac2f74
...
...
@@ -26,7 +26,9 @@ module Gitlab
private
def
create_node
(
key
,
factory
)
factory
.
with
(
value:
@config
[
key
],
key:
key
,
parent:
self
)
factory
.
value
(
config
[
key
])
.
with
(
key:
key
,
parent:
self
,
global:
global
)
factory
.
create!
end
...
...
lib/gitlab/ci/config/node/entry.rb
浏览文件 @
a7ac2f74
...
...
@@ -8,13 +8,17 @@ module Gitlab
class
Entry
class
InvalidError
<
StandardError
;
end
attr_reader
:config
attr_accessor
:key
,
:parent
,
:description
attr_reader
:config
,
:attributes
attr_accessor
:key
,
:parent
,
:
global
,
:
description
def
initialize
(
config
)
def
initialize
(
config
,
**
attributes
)
@config
=
config
@nodes
=
{}
(
@attributes
=
attributes
).
each
do
|
attribute
,
value
|
public_send
(
"
#{
attribute
}
="
,
value
)
end
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
end
...
...
@@ -68,10 +72,6 @@ module Gitlab
true
end
def
attributes
{
key:
@key
,
parent:
@parent
,
description:
@description
}
end
def
self
.
default
end
...
...
lib/gitlab/ci/config/node/factory.rb
浏览文件 @
a7ac2f74
...
...
@@ -13,38 +13,29 @@ module Gitlab
@attributes
=
{}
end
def
value
(
value
)
@value
=
value
self
end
def
with
(
attributes
)
@attributes
.
merge!
(
attributes
)
self
end
def
create!
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:
value
)
raise
InvalidFactory
unless
defined?
(
@
value
)
##
# We assume that unspecified entry is undefined.
# See issue #18775.
#
if
@
attributes
[
:value
]
.
nil?
fabricate
(
Node
::
Undefined
,
@node
)
if
@
value
.
nil?
Node
::
Undefined
.
new
(
@node
,
@attributes
)
else
fabricate
(
@node
,
@attributes
[
:value
]
)
@node
.
new
(
@value
,
@attributes
)
end
end
def
self
.
fabricate
(
node
,
value
,
**
attributes
)
node
.
new
(
value
).
tap
do
|
entry
|
entry
.
key
=
attributes
[
:key
]
entry
.
parent
=
attributes
[
:parent
]
entry
.
description
=
attributes
[
:description
]
end
end
private
def
fabricate
(
node
,
value
)
self
.
class
.
fabricate
(
node
,
value
,
@attributes
)
end
end
end
end
...
...
lib/gitlab/ci/config/node/global.rb
浏览文件 @
a7ac2f74
...
...
@@ -51,6 +51,10 @@ module Gitlab
def
stages
stages_defined?
?
stages_value
:
types_value
end
def
global
self
end
end
end
end
...
...
lib/gitlab/ci/config/node/jobs.rb
浏览文件 @
a7ac2f74
...
...
@@ -30,13 +30,13 @@ module Gitlab
private
def
create_node
(
key
,
value
)
node
=
key
.
to_s
.
start_with?
(
'.'
)
?
Node
::
HiddenJob
:
Node
::
Job
job_
node
=
key
.
to_s
.
start_with?
(
'.'
)
?
Node
::
HiddenJob
:
Node
::
Job
attributes
=
{
key:
key
,
parent:
self
,
description:
"
#{
key
}
job definition."
}
job_
attributes
=
{
key:
key
,
parent:
self
,
description:
"
#{
key
}
job definition."
}
Node
::
Factory
.
fabricate
(
node
,
value
,
attributes
)
job_node
.
new
(
value
,
attributes
.
merge
(
job_attributes
)
)
end
end
end
...
...
lib/gitlab/ci/config/node/undefined.rb
浏览文件 @
a7ac2f74
...
...
@@ -19,7 +19,7 @@ module Gitlab
validates
:config
,
type:
Class
end
def
initialize
(
node
)
def
initialize
(
node
,
**
attributes
)
super
@strategy
=
create_strategy
(
node
,
node
.
default
)
end
...
...
@@ -34,9 +34,7 @@ module Gitlab
if
default
.
nil?
Undefined
::
NullStrategy
.
new
else
entry
=
Node
::
Factory
.
fabricate
(
node
,
default
,
attributes
)
entry
=
node
.
new
(
default
,
attributes
)
Undefined
::
DefaultStrategy
.
new
(
entry
)
end
end
...
...
spec/lib/gitlab/ci/config/node/factory_spec.rb
浏览文件 @
a7ac2f74
...
...
@@ -5,24 +5,10 @@ describe Gitlab::Ci::Config::Node::Factory do
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
let
(
:entry_class
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
describe
'.fabricate'
do
it
'fabricates entry with attributes set'
do
fabricated
=
described_class
.
fabricate
(
entry_class
,
[
'ls'
],
parent:
true
,
key: :test
)
expect
(
fabricated
.
parent
).
to
be
true
expect
(
fabricated
.
key
).
to
eq
:test
expect
(
fabricated
.
value
).
to
eq
[
'ls'
]
expect
(
fabricated
.
attributes
)
.
to
eq
(
parent:
true
,
key: :test
,
description:
nil
)
end
end
context
'when setting up a value'
do
it
'creates entry with valid value'
do
entry
=
factory
.
with
(
value:
[
'ls'
,
'pwd'
])
.
value
(
[
'ls'
,
'pwd'
])
.
create!
expect
(
entry
.
value
).
to
eq
[
'ls'
,
'pwd'
]
...
...
@@ -31,7 +17,7 @@ describe Gitlab::Ci::Config::Node::Factory do
context
'when setting description'
do
it
'creates entry with description'
do
entry
=
factory
.
with
(
value:
[
'ls'
,
'pwd'
])
.
value
(
[
'ls'
,
'pwd'
])
.
with
(
description:
'test description'
)
.
create!
...
...
@@ -43,7 +29,8 @@ describe Gitlab::Ci::Config::Node::Factory do
context
'when setting key'
do
it
'creates entry with custom key'
do
entry
=
factory
.
with
(
value:
[
'ls'
,
'pwd'
],
key:
'test key'
)
.
value
([
'ls'
,
'pwd'
])
.
with
(
key:
'test key'
)
.
create!
expect
(
entry
.
key
).
to
eq
'test key'
...
...
@@ -55,7 +42,8 @@ describe Gitlab::Ci::Config::Node::Factory do
it
'creates entry with valid parent'
do
entry
=
factory
.
with
(
value:
'ls'
,
parent:
parent
)
.
value
(
'ls'
)
.
with
(
parent:
parent
)
.
create!
expect
(
entry
.
parent
).
to
eq
parent
...
...
@@ -74,7 +62,7 @@ describe Gitlab::Ci::Config::Node::Factory do
context
'when creating entry with nil value'
do
it
'creates an undefined entry'
do
entry
=
factory
.
with
(
value:
nil
)
.
value
(
nil
)
.
create!
expect
(
entry
).
to
be_an_instance_of
Gitlab
::
Ci
::
Config
::
Node
::
Undefined
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录