Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ad3be46b
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,发现更多精彩内容 >>
提交
ad3be46b
编写于
12月 08, 2017
作者:
K
Kamil Trzcinski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement and use Gitlab::Ci::Pipeline::Chain::Command
上级
b30e0e06
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
146 addition
and
127 deletion
+146
-127
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+13
-12
lib/gitlab/ci/pipeline/chain/base.rb
lib/gitlab/ci/pipeline/chain/base.rb
+3
-4
lib/gitlab/ci/pipeline/chain/build.rb
lib/gitlab/ci/pipeline/chain/build.rb
+7
-37
lib/gitlab/ci/pipeline/chain/command.rb
lib/gitlab/ci/pipeline/chain/command.rb
+65
-0
lib/gitlab/ci/pipeline/chain/helpers.rb
lib/gitlab/ci/pipeline/chain/helpers.rb
+0
-18
lib/gitlab/ci/pipeline/chain/validate/abilities.rb
lib/gitlab/ci/pipeline/chain/validate/abilities.rb
+6
-6
lib/gitlab/ci/pipeline/chain/validate/repository.rb
lib/gitlab/ci/pipeline/chain/validate/repository.rb
+2
-5
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
+21
-19
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
+3
-3
spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
+1
-1
spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb
spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb
+5
-4
spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb
spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb
+3
-2
spec/lib/gitlab/ci/pipeline/chain/validate/config_spec.rb
spec/lib/gitlab/ci/pipeline/chain/validate/config_spec.rb
+4
-3
spec/lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb
.../lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb
+13
-13
未找到文件。
app/services/ci/create_pipeline_service.rb
浏览文件 @
ad3be46b
...
...
@@ -12,7 +12,8 @@ module Ci
def
execute
(
source
,
ignore_skip_ci:
false
,
save_on_errors:
true
,
trigger_request:
nil
,
schedule:
nil
,
&
block
)
@pipeline
=
Ci
::
Pipeline
.
new
command
=
OpenStruct
.
new
(
source:
source
,
command
=
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
source:
source
,
origin_ref:
params
[
:ref
],
checkout_sha:
params
[
:checkout_sha
],
after_sha:
params
[
:after
],
...
...
lib/gitlab/ci/pipeline/chain/base.rb
浏览文件 @
ad3be46b
...
...
@@ -3,14 +3,13 @@ module Gitlab
module
Pipeline
module
Chain
class
Base
attr_reader
:pipeline
,
:project
,
:current_user
attr_reader
:pipeline
,
:command
delegate
:project
,
:current_user
,
to: :command
def
initialize
(
pipeline
,
command
)
@pipeline
=
pipeline
@command
=
command
@project
=
command
.
project
@current_user
=
command
.
current_user
end
def
perform!
...
...
lib/gitlab/ci/pipeline/chain/build.rb
浏览文件 @
ad3be46b
...
...
@@ -6,15 +6,15 @@ module Gitlab
def
perform!
@pipeline
.
assign_attributes
(
source:
@command
.
source
,
project:
@project
,
ref:
ref
,
sha:
sha
,
before_sha:
before_sha
,
tag:
tag_exists?
,
project:
@
command
.
project
,
ref:
@command
.
ref
,
sha:
@command
.
sha
,
before_sha:
@command
.
before_sha
,
tag:
@command
.
tag_exists?
,
trigger_requests:
Array
(
@command
.
trigger_request
),
user:
@current_user
,
user:
@c
ommand
.
c
urrent_user
,
pipeline_schedule:
@command
.
schedule
,
protected:
protected_ref?
protected:
@command
.
protected_ref?
)
@pipeline
.
set_config_source
...
...
@@ -23,36 +23,6 @@ module Gitlab
def
break?
false
end
private
def
ref
@ref
||=
Gitlab
::
Git
.
ref_name
(
origin_ref
)
end
def
sha
@project
.
commit
(
origin_sha
||
origin_ref
).
try
(
:id
)
end
def
origin_ref
@command
.
origin_ref
end
def
origin_sha
@command
.
checkout_sha
||
@command
.
after_sha
end
def
before_sha
@command
.
checkout_sha
||
@command
.
before_sha
||
Gitlab
::
Git
::
BLANK_SHA
end
def
protected_ref?
@project
.
protected_for?
(
ref
)
end
def
tag_exists?
project
.
repository
.
tag_exists?
(
ref
)
end
end
end
end
...
...
lib/gitlab/ci/pipeline/chain/command.rb
0 → 100644
浏览文件 @
ad3be46b
module
Gitlab
module
Ci
module
Pipeline
module
Chain
Command
=
Struct
.
new
(
:source
,
:project
,
:current_user
,
:origin_ref
,
:checkout_sha
,
:after_sha
,
:before_sha
,
:trigger_request
,
:schedule
,
:ignore_skip_ci
,
:save_incompleted
,
:seeds_block
)
do
include
Gitlab
::
Utils
::
StrongMemoize
def
initialize
(
**
params
)
params
.
each
do
|
key
,
value
|
self
[
key
]
=
value
end
end
def
branch_exists?
strong_memoize
(
:is_branch
)
do
project
.
repository
.
branch_exists?
(
ref
)
end
end
def
tag_exists?
strong_memoize
(
:is_tag
)
do
project
.
repository
.
tag_exists?
(
ref
)
end
end
def
ref
strong_memoize
(
:ref
)
do
Gitlab
::
Git
.
ref_name
(
origin_ref
)
end
end
def
sha
strong_memoize
(
:sha
)
do
project
.
commit
(
origin_sha
||
origin_ref
).
try
(
:id
)
end
end
def
origin_sha
checkout_sha
||
after_sha
end
def
before_sha
checkout_sha
||
before_sha
||
Gitlab
::
Git
::
BLANK_SHA
end
def
protected_ref?
strong_memoize
(
:protected_ref
)
do
project
.
protected_for?
(
ref
)
end
end
def
error
(
message
)
pipeline
.
errors
.
add
(
:base
,
message
)
end
end
end
end
end
end
lib/gitlab/ci/pipeline/chain/helpers.rb
浏览文件 @
ad3be46b
...
...
@@ -3,24 +3,6 @@ module Gitlab
module
Pipeline
module
Chain
module
Helpers
include
Gitlab
::
Utils
::
StrongMemoize
def
branch_exists?
strong_memoize
(
:is_branch
)
do
raise
ArgumentError
unless
pipeline
.
ref
project
.
repository
.
branch_exists?
(
pipeline
.
ref
)
end
end
def
tag_exists?
strong_memoize
(
:is_tag
)
do
raise
ArgumentError
unless
pipeline
.
ref
project
.
repository
.
tag_exists?
(
pipeline
.
ref
)
end
end
def
error
(
message
)
pipeline
.
errors
.
add
(
:base
,
message
)
end
...
...
lib/gitlab/ci/pipeline/chain/validate/abilities.rb
浏览文件 @
ad3be46b
...
...
@@ -14,7 +14,7 @@ module Gitlab
unless
allowed_to_trigger_pipeline?
if
can?
(
current_user
,
:create_pipeline
,
project
)
return
error
(
"Insufficient permissions for protected ref '
#{
pipeline
.
ref
}
'"
)
return
error
(
"Insufficient permissions for protected ref '
#{
command
.
ref
}
'"
)
else
return
error
(
'Insufficient permissions to create a new pipeline'
)
end
...
...
@@ -29,7 +29,7 @@ module Gitlab
if
current_user
allowed_to_create?
else
# legacy triggers don't have a corresponding user
!
project
.
protected_for?
(
@pipeline
.
ref
)
!
@command
.
protected_ref?
end
end
...
...
@@ -38,10 +38,10 @@ module Gitlab
access
=
Gitlab
::
UserAccess
.
new
(
current_user
,
project:
project
)
if
branch_exists?
access
.
can_update_branch?
(
@
pipeline
.
ref
)
elsif
tag_exists?
access
.
can_create_tag?
(
@
pipeline
.
ref
)
if
@command
.
branch_exists?
access
.
can_update_branch?
(
@
command
.
ref
)
elsif
@command
.
tag_exists?
access
.
can_create_tag?
(
@
command
.
ref
)
else
true
# Allow it for now and we'll reject when we check ref existence
end
...
...
lib/gitlab/ci/pipeline/chain/validate/repository.rb
浏览文件 @
ad3be46b
...
...
@@ -7,14 +7,11 @@ module Gitlab
include
Chain
::
Helpers
def
perform!
unless
branch_exists?
||
tag_exists?
unless
@command
.
branch_exists?
||
@command
.
tag_exists?
return
error
(
'Reference not found'
)
end
## TODO, we check commit in the service, that is why
# there is no repository access here.
#
unless
pipeline
.
sha
unless
@command
.
sha
return
error
(
'Commit not found'
)
end
end
...
...
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
浏览文件 @
ad3be46b
...
...
@@ -6,7 +6,8 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
let
(
:pipeline
)
{
Ci
::
Pipeline
.
new
}
let
(
:command
)
do
double
(
'command'
,
source: :push
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
source: :push
,
origin_ref:
'master'
,
checkout_sha:
project
.
commit
.
id
,
after_sha:
nil
,
...
...
@@ -60,7 +61,8 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
context
'when pipeline is running for a tag'
do
let
(
:command
)
do
double
(
'command'
,
source: :push
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
source: :push
,
origin_ref:
'mytag'
,
checkout_sha:
project
.
commit
.
id
,
after_sha:
nil
,
...
...
@@ -72,7 +74,7 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
end
before
do
allow
(
step
).
to
receive
(
:tag_exists?
).
and_return
(
true
)
allow
_any_instance_of
(
Repository
).
to
receive
(
:tag_exists?
).
with
(
'mytag'
).
and_return
(
true
)
step
.
perform!
end
...
...
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
浏览文件 @
ad3be46b
...
...
@@ -10,9 +10,9 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
end
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
,
seeds_block:
nil
)
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
seeds_block:
nil
)
end
let
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
...
...
spec/lib/gitlab/ci/pipeline/chain/sequence_spec.rb
浏览文件 @
ad3be46b
...
...
@@ -5,7 +5,7 @@ describe Gitlab::Ci::Pipeline::Chain::Sequence do
set
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
{
build_stubbed
(
:ci_pipeline
)
}
let
(
:command
)
{
double
(
'command'
)
}
let
(
:command
)
{
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
}
let
(
:first_step
)
{
spy
(
'first step'
)
}
let
(
:second_step
)
{
spy
(
'second step'
)
}
let
(
:sequence
)
{
[
first_step
,
second_step
]
}
...
...
spec/lib/gitlab/ci/pipeline/chain/skip_spec.rb
浏览文件 @
ad3be46b
...
...
@@ -6,7 +6,8 @@ describe Gitlab::Ci::Pipeline::Chain::Skip do
set
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:command
)
do
double
(
'command'
,
project:
project
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
ignore_skip_ci:
false
,
save_incompleted:
true
)
...
...
spec/lib/gitlab/ci/pipeline/chain/validate/abilities_spec.rb
浏览文件 @
ad3be46b
...
...
@@ -5,11 +5,12 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do
set
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
do
build_stubbed
(
:ci_pipeline
,
ref:
ref
,
project:
project
)
build_stubbed
(
:ci_pipeline
,
project:
project
)
end
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
)
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
origin_ref:
ref
)
end
let
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
...
...
spec/lib/gitlab/ci/pipeline/chain/validate/config_spec.rb
浏览文件 @
ad3be46b
...
...
@@ -5,7 +5,8 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Config do
set
(
:user
)
{
create
(
:user
)
}
let
(
:command
)
do
double
(
'command'
,
project:
project
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
save_incompleted:
true
)
end
...
...
spec/lib/gitlab/ci/pipeline/chain/validate/repository_spec.rb
浏览文件 @
ad3be46b
...
...
@@ -3,10 +3,7 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
::
Repository
do
set
(
:project
)
{
create
(
:project
,
:repository
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:command
)
do
double
(
'command'
,
project:
project
,
current_user:
user
)
end
let
(
:pipeline
)
{
build_stubbed
(
:ci_pipeline
)
}
let!
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
...
...
@@ -14,9 +11,10 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Repository do
step
.
perform!
end
context
'when pipeline ref and sha exists'
do
let
(
:pipeline
)
do
build_stubbed
(
:ci_pipeline
,
ref:
'master'
,
sha:
'123'
,
project:
project
)
context
'when ref and sha exists'
do
let
(
:command
)
do
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
origin_ref:
'master'
,
checkout_sha:
project
.
commit
.
id
)
end
it
'does not break the chain'
do
...
...
@@ -28,9 +26,10 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Repository do
end
end
context
'when pipeline ref does not exist'
do
let
(
:pipeline
)
do
build_stubbed
(
:ci_pipeline
,
ref:
'something'
,
project:
project
)
context
'when ref does not exist'
do
let
(
:command
)
do
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
origin_ref:
'something'
)
end
it
'breaks the chain'
do
...
...
@@ -43,9 +42,10 @@ describe Gitlab::Ci::Pipeline::Chain::Validate::Repository do
end
end
context
'when pipeline does not have SHA set'
do
let
(
:pipeline
)
do
build_stubbed
(
:ci_pipeline
,
ref:
'master'
,
sha:
nil
,
project:
project
)
context
'when does not have existing SHA set'
do
let
(
:command
)
do
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Command
.
new
(
project:
project
,
current_user:
user
,
origin_ref:
'master'
,
checkout_sha:
'something'
)
end
it
'breaks the chain'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录