Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
75130a41
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,发现更多精彩内容 >>
提交
75130a41
编写于
8月 24, 2017
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove CreateTriggerRequestService and forbit to save variables on Ci::TriggerRequest
上级
970af996
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
53 addition
and
95 deletion
+53
-95
app/models/ci/trigger_request.rb
app/models/ci/trigger_request.rb
+4
-0
app/services/ci/create_trigger_request_service.rb
app/services/ci/create_trigger_request_service.rb
+0
-19
lib/api/triggers.rb
lib/api/triggers.rb
+4
-4
lib/api/v3/triggers.rb
lib/api/v3/triggers.rb
+19
-12
spec/factories/ci/trigger_requests.rb
spec/factories/ci/trigger_requests.rb
+9
-8
spec/models/ci/trigger_request_spec.rb
spec/models/ci/trigger_request_spec.rb
+17
-0
spec/services/ci/create_trigger_request_service_spec.rb
spec/services/ci/create_trigger_request_service_spec.rb
+0
-52
未找到文件。
app/models/ci/trigger_request.rb
浏览文件 @
75130a41
...
@@ -6,6 +6,10 @@ module Ci
...
@@ -6,6 +6,10 @@ module Ci
belongs_to
:pipeline
,
foreign_key: :commit_id
belongs_to
:pipeline
,
foreign_key: :commit_id
has_many
:builds
has_many
:builds
# Ws swtiched to Ci::PipelineVariable from Ci::TriggerRequest.variables.
# Ci::TriggerRequest doesn't save variables anymore.
validates
:variables
,
absence:
true
serialize
:variables
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:variables
# rubocop:disable Cop/ActiveRecordSerialize
def
user_variables
def
user_variables
...
...
app/services/ci/create_trigger_request_service.rb
已删除
100644 → 0
浏览文件 @
970af996
# This class is deprecated because we're closing Ci::TriggerRequest.
# New class is PipelineTriggerService (app/services/ci/pipeline_trigger_service.rb)
# which is integrated with Ci::PipelineVariable instaed of Ci::TriggerRequest.
# We remove this class after we removed v1 and v3 API. This class is still being
# referred by such legacy code.
module
Ci
module
CreateTriggerRequestService
Result
=
Struct
.
new
(
:trigger_request
,
:pipeline
)
def
self
.
execute
(
project
,
trigger
,
ref
,
variables
=
nil
)
trigger_request
=
trigger
.
trigger_requests
.
create
(
variables:
variables
)
pipeline
=
Ci
::
CreatePipelineService
.
new
(
project
,
trigger
.
owner
,
ref:
ref
)
.
execute
(
:trigger
,
ignore_skip_ci:
true
,
trigger_request:
trigger_request
)
Result
.
new
(
trigger_request
,
pipeline
)
end
end
end
lib/api/triggers.rb
浏览文件 @
75130a41
...
@@ -15,16 +15,16 @@ module API
...
@@ -15,16 +15,16 @@ module API
optional
:variables
,
type:
Hash
,
desc:
'The list of variables to be injected into build'
optional
:variables
,
type:
Hash
,
desc:
'The list of variables to be injected into build'
end
end
post
":id/(ref/:ref/)trigger/pipeline"
,
requirements:
{
ref:
/.+/
}
do
post
":id/(ref/:ref/)trigger/pipeline"
,
requirements:
{
ref:
/.+/
}
do
authenticate!
authorize!
:admin_build
,
user_project
# validate variables
# validate variables
params
[
:variables
]
=
params
[
:variables
].
to_h
params
[
:variables
]
=
params
[
:variables
].
to_h
unless
params
[
:variables
].
all?
{
|
key
,
value
|
key
.
is_a?
(
String
)
&&
value
.
is_a?
(
String
)
}
unless
params
[
:variables
].
all?
{
|
key
,
value
|
key
.
is_a?
(
String
)
&&
value
.
is_a?
(
String
)
}
render_api_error!
(
'variables needs to be a map of key-valued strings'
,
400
)
render_api_error!
(
'variables needs to be a map of key-valued strings'
,
400
)
end
end
project
=
find_project
(
params
[
:id
])
result
=
Ci
::
PipelineTriggerService
.
new
(
user_project
,
nil
,
params
).
execute
not_found!
unless
project
result
=
Ci
::
PipelineTriggerService
.
new
(
project
,
nil
,
params
).
execute
not_found!
unless
result
not_found!
unless
result
if
result
[
:http_status
]
if
result
[
:http_status
]
...
...
lib/api/v3/triggers.rb
浏览文件 @
75130a41
...
@@ -16,25 +16,32 @@ module API
...
@@ -16,25 +16,32 @@ module API
optional
:variables
,
type:
Hash
,
desc:
'The list of variables to be injected into build'
optional
:variables
,
type:
Hash
,
desc:
'The list of variables to be injected into build'
end
end
post
":id/(ref/:ref/)trigger/builds"
,
requirements:
{
ref:
/.+/
}
do
post
":id/(ref/:ref/)trigger/builds"
,
requirements:
{
ref:
/.+/
}
do
project
=
find_project
(
params
[
:id
])
authenticate!
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
].
to_s
)
authorize!
:admin_build
,
user_project
not_found!
unless
project
&&
trigger
unauthorized!
unless
trigger
.
project
==
project
# validate variables
# validate variables
variables
=
params
[
:variables
].
to_h
params
[
:variables
]
=
params
[
:variables
].
to_h
unless
variables
.
all?
{
|
key
,
value
|
key
.
is_a?
(
String
)
&&
value
.
is_a?
(
String
)
}
unless
params
[
:variables
]
.
all?
{
|
key
,
value
|
key
.
is_a?
(
String
)
&&
value
.
is_a?
(
String
)
}
render_api_error!
(
'variables needs to be a map of key-valued strings'
,
400
)
render_api_error!
(
'variables needs to be a map of key-valued strings'
,
400
)
end
end
# create request and trigger builds
result
=
Ci
::
PipelineTriggerService
.
new
(
user_project
,
nil
,
params
).
execute
result
=
Ci
::
CreateTriggerRequestService
.
execute
(
project
,
trigger
,
params
[
:ref
].
to_s
,
variables
)
not_found!
unless
result
pipeline
=
result
.
pipeline
if
pipeline
.
persisted?
if
result
[
:http_status
]
present
result
.
trigger_request
,
with:
::
API
::
V3
::
Entities
::
TriggerRequest
render_api_error!
(
result
[
:message
],
result
[
:http_status
])
else
else
render_validation_error!
(
pipeline
)
pipeline
=
result
[
:pipeline
]
trigger_request
=
pipeline
.
trigger_request
# Ws swtiched to Ci::PipelineVariable from Ci::TriggerRequest.variables.
# Ci::TriggerRequest doesn't save variables anymore.
# Although, to prevent braking compatibility, copying variables and present it as Ci::TriggerRequest.
pipeline
.
variables
.
each
do
|
variable
|
trigger_request
.
variables
<<
{
key:
variable
.
key
,
value:
variable
.
value
}
end
present
trigger_request
,
with:
::
API
::
V3
::
Entities
::
TriggerRequest
end
end
end
end
...
...
spec/factories/ci/trigger_requests.rb
浏览文件 @
75130a41
...
@@ -2,13 +2,14 @@ FactoryGirl.define do
...
@@ -2,13 +2,14 @@ FactoryGirl.define do
factory
:ci_trigger_request
,
class:
Ci
::
TriggerRequest
do
factory
:ci_trigger_request
,
class:
Ci
::
TriggerRequest
do
trigger
factory: :ci_trigger
trigger
factory: :ci_trigger
factory
:ci_trigger_request_with_variables
do
# TODO:
variables
do
# factory :ci_trigger_request_with_variables do
{
# variables do
TRIGGER_KEY_1
:
'TRIGGER_VALUE_1'
,
# {
TRIGGER_KEY_2
:
'TRIGGER_VALUE_2'
# TRIGGER_KEY_1: 'TRIGGER_VALUE_1',
}
# TRIGGER_KEY_2: 'TRIGGER_VALUE_2'
end
# }
end
# end
# end
end
end
end
end
spec/models/ci/trigger_request_spec.rb
0 → 100644
浏览文件 @
75130a41
require
'spec_helper'
describe
Ci
::
TriggerRequest
do
describe
'validation'
do
it
'be invalid if saving a variable'
do
trigger
=
build
(
:ci_trigger_request
,
variables:
{
TRIGGER_KEY_1
:
'TRIGGER_VALUE_1'
}
)
expect
(
trigger
.
valid?
).
to
be_falsey
end
it
'be valid if not saving a variable'
do
trigger
=
build
(
:ci_trigger_request
)
expect
(
trigger
.
valid?
).
to
be_truthy
end
end
end
spec/services/ci/create_trigger_request_service_spec.rb
已删除
100644 → 0
浏览文件 @
970af996
require
'spec_helper'
describe
Ci
::
CreateTriggerRequestService
do
let
(
:service
)
{
described_class
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:trigger
)
{
create
(
:ci_trigger
,
project:
project
,
owner:
owner
)
}
let
(
:owner
)
{
create
(
:user
)
}
before
do
stub_ci_pipeline_to_return_yaml_file
project
.
add_developer
(
owner
)
end
describe
'#execute'
do
context
'valid params'
do
subject
{
service
.
execute
(
project
,
trigger
,
'master'
)
}
context
'without owner'
do
it
{
expect
(
subject
.
trigger_request
).
to
be_kind_of
(
Ci
::
TriggerRequest
)
}
it
{
expect
(
subject
.
trigger_request
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
it
{
expect
(
subject
.
pipeline
).
to
be_kind_of
(
Ci
::
Pipeline
)
}
it
{
expect
(
subject
.
pipeline
).
to
be_trigger
}
end
context
'with owner'
do
it
{
expect
(
subject
.
trigger_request
).
to
be_kind_of
(
Ci
::
TriggerRequest
)
}
it
{
expect
(
subject
.
trigger_request
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
}
it
{
expect
(
subject
.
trigger_request
.
builds
.
first
.
user
).
to
eq
(
owner
)
}
it
{
expect
(
subject
.
pipeline
).
to
be_kind_of
(
Ci
::
Pipeline
)
}
it
{
expect
(
subject
.
pipeline
).
to
be_trigger
}
it
{
expect
(
subject
.
pipeline
.
user
).
to
eq
(
owner
)
}
end
end
context
'no commit for ref'
do
subject
{
service
.
execute
(
project
,
trigger
,
'other-branch'
)
}
it
{
expect
(
subject
.
pipeline
).
not_to
be_persisted
}
end
context
'no builds created'
do
subject
{
service
.
execute
(
project
,
trigger
,
'master'
)
}
before
do
stub_ci_pipeline_yaml_file
(
'script: { only: [develop], script: hello World }'
)
end
it
{
expect
(
subject
.
pipeline
).
not_to
be_persisted
}
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录