Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ef60b8e1
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,发现更多精彩内容 >>
提交
ef60b8e1
编写于
5月 18, 2016
作者:
K
Kamil Trzcinski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use pipelines.errors when communicating the error
上级
379dc6fb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
31 deletion
+41
-31
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+6
-8
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+22
-14
app/views/projects/pipelines/new.html.haml
app/views/projects/pipelines/new.html.haml
+2
-5
spec/features/pipelines_spec.rb
spec/features/pipelines_spec.rb
+11
-4
未找到文件。
app/controllers/projects/pipelines_controller.rb
浏览文件 @
ef60b8e1
...
...
@@ -15,19 +15,17 @@ class Projects::PipelinesController < Projects::ApplicationController
end
def
new
@pipeline
=
project
.
ci_commits
.
new
end
def
create
begin
pipeline
=
Ci
::
CreatePipelineService
.
new
(
project
,
current_user
,
create_params
).
execute
redirect_to
namespace_project_pipeline_path
(
project
.
namespace
,
project
,
pipeline
)
rescue
ArgumentError
=>
e
flash
[
:alert
]
=
e
.
message
render
'new'
rescue
flash
[
:alert
]
=
'The pipeline could not be created. Please try again.'
@pipeline
=
Ci
::
CreatePipelineService
.
new
(
project
,
current_user
,
create_params
).
execute
unless
@pipeline
.
persisted?
render
'new'
return
end
redirect_to
namespace_project_pipeline_path
(
project
.
namespace
,
project
,
@pipeline
)
end
def
show
...
...
app/services/ci/create_pipeline_service.rb
浏览文件 @
ef60b8e1
module
Ci
class
CreatePipelineService
<
BaseService
def
execute
pipeline
=
project
.
ci_commits
.
new
unless
ref_names
.
include?
(
params
[
:ref
])
raise
ArgumentError
,
'Reference not found'
pipeline
.
errors
.
add
(
:base
,
'Reference not found'
)
return
pipeline
end
unless
commit
raise
ArgumentError
,
'Commit not found'
pipeline
.
errors
.
add
(
:base
,
'Commit not found'
)
return
pipeline
end
unless
can?
(
current_user
,
:create_pipeline
,
project
)
raise
RuntimeError
,
'Insufficient permissions to create a new pipeline'
pipeline
.
errors
.
add
(
:base
,
'Insufficient permissions to create a new pipeline'
)
return
pipeline
end
pipeline
=
new_pipeline
begin
Ci
::
Commit
.
transaction
do
pipeline
.
sha
=
commit
.
id
pipeline
.
ref
=
params
[
:ref
]
pipeline
.
before_sha
=
Gitlab
::
Git
::
BLANK_SHA
Ci
::
Commit
.
transaction
do
unless
pipeline
.
config_processor
raise
ArgumentError
,
pipeline
.
yaml_errors
||
'Missing .gitlab-ci.yml file'
end
unless
pipeline
.
config_processor
pipeline
.
errors
.
add
(
:base
,
pipeline
.
yaml_errors
||
'Missing .gitlab-ci.yml file'
)
raise
ActiveRecord
::
Rollback
end
pipeline
.
save!
pipeline
.
create_builds
(
current_user
)
pipeline
.
save!
pipeline
.
create_builds
(
current_user
)
end
rescue
pipeline
.
errors
.
add
(
:base
,
'The pipeline could not be created. Please try again.'
)
end
pipeline
...
...
@@ -29,10 +41,6 @@ module Ci
private
def
new_pipeline
project
.
ci_commits
.
new
(
sha:
commit
.
id
,
ref:
params
[
:ref
],
before_sha:
Gitlab
::
Git
::
BLANK_SHA
)
end
def
ref_names
@ref_names
||=
project
.
repository
.
ref_names
end
...
...
app/views/projects/pipelines/new.html.haml
浏览文件 @
ef60b8e1
-
page_title
"New Pipeline"
=
render
"header_title"
-
if
@error
.alert.alert-danger
%button
{
type:
"button"
,
class:
"close"
,
"data-dismiss"
=>
"alert"
}
×
=
@error
%h3
.page-title
New Pipeline
%hr
=
form_tag
namespace_project_pipelines_path
,
method: :post
,
id:
"new-pipeline-form"
,
class:
"form-horizontal js-new-pipeline-form js-requires-input"
do
=
form_for
@pipeline
,
url:
namespace_project_pipelines_path
(
@project
.
namespace
,
@project
),
html:
{
id:
"new-pipeline-form"
,
class:
"form-horizontal js-new-pipeline-form js-requires-input"
}
do
=
form_errors
(
@pipeline
)
.form-group
=
label_tag
:ref
,
'Create for'
,
class:
'control-label'
.col-sm-10
...
...
spec/features/pipelines_spec.rb
浏览文件 @
ef60b8e1
...
...
@@ -126,12 +126,19 @@ describe "Pipelines" do
before
{
visit
new_namespace_project_pipeline_path
(
project
.
namespace
,
project
)
}
context
'for valid commit'
do
before
do
fill_in
(
'Create for'
,
with:
'master'
)
stub_ci_commit_to_return_yaml_file
before
{
fill_in
(
'Create for'
,
with:
'master'
)
}
context
'with gitlab-ci.yml'
do
before
{
stub_ci_commit_to_return_yaml_file
}
it
{
expect
{
click_on
'Create pipeline'
}.
to
change
{
Ci
::
Commit
.
count
}.
by
(
1
)
}
end
it
{
expect
{
click_on
'Create pipeline'
}.
to
change
{
Ci
::
Commit
.
count
}.
by
(
1
)
}
context
'without gitlab-ci.yml'
do
before
{
click_on
'Create pipeline'
}
it
{
expect
(
page
).
to
have_content
(
'Missing .gitlab-ci.yml file'
)
}
end
end
context
'for invalid commit'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录