BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
ef60b8e1
Commit
ef60b8e1
authored
May 18, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use pipelines.errors when communicating the error
parent
379dc6fb
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
27 deletions
+37
-27
pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+6
-8
create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+18
-10
new.html.haml
app/views/projects/pipelines/new.html.haml
+2
-5
pipelines_spec.rb
spec/features/pipelines_spec.rb
+11
-4
No files found.
app/controllers/projects/pipelines_controller.rb
View file @
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
View file @
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
unless
pipeline
.
config_processor
raise
ArgumentError
,
pipeline
.
yaml_errors
||
'Missing .gitlab-ci.yml file'
pipeline
.
errors
.
add
(
:base
,
pipeline
.
yaml_errors
||
'Missing .gitlab-ci.yml file'
)
raise
ActiveRecord
::
Rollback
end
pipeline
.
save!
pipeline
.
create_builds
(
current_user
)
end
rescue
pipeline
.
errors
.
add
(
:base
,
'The pipeline could not be created. Please try again.'
)
end
pipeline
end
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
View file @
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
View file @
ef60b8e1
...
...
@@ -126,14 +126,21 @@ 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
end
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
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
before
do
fill_in
(
'Create for'
,
with:
'invalid reference'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment