Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
57753b7b
Commit
57753b7b
authored
Aug 19, 2020
by
Furkan Ayhan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement JSON response for project/pipelines create
This will be used in new pipeline form.
parent
bb6cbf20
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
4 deletions
+79
-4
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+18
-4
changelogs/unreleased/231344-json-result-for-project-pipeline-create.yml
...leased/231344-json-result-for-project-pipeline-create.yml
+5
-0
spec/controllers/projects/pipelines_controller_spec.rb
spec/controllers/projects/pipelines_controller_spec.rb
+56
-0
No files found.
app/controllers/projects/pipelines_controller.rb
View file @
57753b7b
...
...
@@ -63,10 +63,24 @@ class Projects::PipelinesController < Projects::ApplicationController
.
new
(
project
,
current_user
,
create_params
)
.
execute
(
:web
,
ignore_skip_ci:
true
,
save_on_errors:
false
)
if
@pipeline
.
created_successfully?
redirect_to
project_pipeline_path
(
project
,
@pipeline
)
else
render
'new'
,
status: :bad_request
respond_to
do
|
format
|
format
.
html
do
if
@pipeline
.
created_successfully?
redirect_to
project_pipeline_path
(
project
,
@pipeline
)
else
render
'new'
,
status: :bad_request
end
end
format
.
json
do
if
@pipeline
.
created_successfully?
render
json:
PipelineSerializer
.
new
(
project:
project
,
current_user:
current_user
)
.
represent
(
@pipeline
),
status: :created
else
render
json:
@pipeline
.
errors
,
status: :bad_request
end
end
end
end
...
...
changelogs/unreleased/231344-json-result-for-project-pipeline-create.yml
0 → 100644
View file @
57753b7b
---
title
:
Implement JSON response for project/pipelines create
merge_request
:
39839
author
:
type
:
other
spec/controllers/projects/pipelines_controller_spec.rb
View file @
57753b7b
...
...
@@ -763,6 +763,62 @@ RSpec.describe Projects::PipelinesController do
end
end
describe
'POST create.json'
do
let
(
:project
)
{
create
(
:project
,
:public
,
:repository
)
}
subject
do
post
:create
,
params:
{
namespace_id:
project
.
namespace
,
project_id:
project
,
pipeline:
{
ref:
'master'
}
},
format: :json
end
before
do
project
.
add_developer
(
user
)
project
.
project_feature
.
update
(
builds_access_level:
feature
)
end
context
'with a valid .gitlab-ci.yml file'
do
before
do
stub_ci_pipeline_yaml_file
(
YAML
.
dump
({
test:
{
stage:
'test'
,
script:
'echo'
}
}))
end
it
'creates a pipeline'
do
expect
{
subject
}.
to
change
{
project
.
ci_pipelines
.
count
}.
by
(
1
)
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
json_response
[
'id'
]).
to
eq
(
project
.
ci_pipelines
.
last
.
id
)
end
end
context
'with an invalid .gitlab-ci.yml file'
do
before
do
stub_ci_pipeline_yaml_file
(
YAML
.
dump
({
test:
{
stage:
'invalid'
,
script:
'echo'
}
}))
end
it
'does not create a pipeline'
do
expect
{
subject
}.
not_to
change
{
project
.
ci_pipelines
.
count
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'base'
]).
to
include
(
'test job: chosen stage does not exist; available stages are .pre, build, test, deploy, .post'
)
end
end
end
describe
'POST retry.json'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
:failed
,
project:
project
)
}
let!
(
:build
)
{
create
(
:ci_build
,
:failed
,
pipeline:
pipeline
)
}
...
...
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