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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
de7b8e51
Commit
de7b8e51
authored
Aug 17, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add endpoints for pipelines
parent
ac73de50
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
208 additions
and
18 deletions
+208
-18
CHANGELOG
CHANGELOG
+1
-0
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+8
-0
lib/api/pipelines.rb
lib/api/pipelines.rb
+74
-0
spec/factories/ci/pipelines.rb
spec/factories/ci/pipelines.rb
+0
-18
spec/requests/api/pipelines_spec.rb
spec/requests/api/pipelines_spec.rb
+124
-0
No files found.
CHANGELOG
View file @
de7b8e51
...
@@ -51,6 +51,7 @@ v 8.11.0 (unreleased)
...
@@ -51,6 +51,7 @@ v 8.11.0 (unreleased)
- Show deployment status on merge requests with external URLs
- Show deployment status on merge requests with external URLs
- Clean up unused routes (Josef Strzibny)
- Clean up unused routes (Josef Strzibny)
- Fix issue on empty project to allow developers to only push to protected branches if given permission
- Fix issue on empty project to allow developers to only push to protected branches if given permission
- API: Add enpoints for pipelines
- Add green outline to New Branch button. !5447 (winniehell)
- Add green outline to New Branch button. !5447 (winniehell)
- Optimize generating of cache keys for issues and notes
- Optimize generating of cache keys for issues and notes
- Improve performance of syntax highlighting Markdown code blocks
- Improve performance of syntax highlighting Markdown code blocks
...
...
lib/api/api.rb
View file @
de7b8e51
...
@@ -56,6 +56,7 @@ module API
...
@@ -56,6 +56,7 @@ module API
mount
::
API
::
Milestones
mount
::
API
::
Milestones
mount
::
API
::
Namespaces
mount
::
API
::
Namespaces
mount
::
API
::
Notes
mount
::
API
::
Notes
mount
::
API
::
Pipelines
mount
::
API
::
ProjectHooks
mount
::
API
::
ProjectHooks
mount
::
API
::
ProjectSnippets
mount
::
API
::
ProjectSnippets
mount
::
API
::
Projects
mount
::
API
::
Projects
...
...
lib/api/entities.rb
View file @
de7b8e51
...
@@ -502,6 +502,14 @@ module API
...
@@ -502,6 +502,14 @@ module API
expose
:key
,
:value
expose
:key
,
:value
end
end
class
Pipeline
<
Grape
::
Entity
expose
:status
,
:ref
,
:sha
,
:before_sha
,
:tag
,
:yaml_errors
expose
:user
,
with:
Entities
::
UserBasic
expose
:created_at
,
:updated_at
,
:started_at
,
:finished_at
,
:committed_at
expose
:duration
end
class
Environment
<
Grape
::
Entity
class
Environment
<
Grape
::
Entity
expose
:id
,
:name
,
:external_url
expose
:id
,
:name
,
:external_url
end
end
...
...
lib/api/pipelines.rb
0 → 100644
View file @
de7b8e51
module
API
class
Pipelines
<
Grape
::
API
before
{
authenticate!
}
params
do
requires
:id
,
type:
String
,
desc:
'The project ID'
end
resource
:projects
do
desc
'Get all Pipelines of the project'
do
detail
'This feature was introduced in GitLab 8.11.'
success
Entities
::
Pipeline
end
params
do
optional
:page
,
type:
Integer
,
desc:
'Page number of the current request'
optional
:per_page
,
type:
Integer
,
desc:
'Number of items per page'
end
get
':id/pipelines'
do
authorize!
:read_pipeline
,
user_project
present
paginate
(
user_project
.
pipelines
),
with:
Entities
::
Pipeline
end
desc
'Gets a specific pipeline for the project'
do
detail
'This feature was introduced in GitLab 8.11'
success
Entities
::
Pipeline
end
params
do
requires
:pipeline_id
,
type:
Integer
,
desc:
'The pipeline ID'
end
get
':id/pipelines/:pipeline_id'
do
authorize!
:read_pipeline
,
user_project
present
pipeline
,
with:
Entities
::
Pipeline
end
desc
'Retry failed builds in the pipeline'
do
detail
'This feature was introduced in GitLab 8.11.'
success
Entities
::
Pipeline
end
params
do
requires
:pipeline_id
,
type:
Integer
,
desc:
'The pipeline ID'
end
post
':id/pipelines/:pipeline_id/retry'
do
authorize!
:update_pipeline
,
user_project
pipeline
.
retry_failed
(
current_user
)
present
pipeline
,
with:
Entities
::
Pipeline
end
desc
'Cancel all builds in the pipeline'
do
detail
'This feature was introduced in GitLab 8.11.'
success
Entities
::
Pipeline
end
params
do
requires
:pipeline_id
,
type:
Integer
,
desc:
'The pipeline ID'
end
post
':id/pipelines/:pipeline_id/cancel'
do
authorize!
:update_pipeline
,
user_project
pipeline
.
cancel_running
status
200
present
pipeline
.
reload
,
with:
Entities
::
Pipeline
end
end
helpers
do
def
pipeline
@pipeline
||=
user_project
.
pipelines
.
find
(
params
[
:pipeline_id
])
end
end
end
end
spec/factories/ci/pipelines.rb
View file @
de7b8e51
# == Schema Information
#
# Table name: commits
#
# id :integer not null, primary key
# project_id :integer
# ref :string(255)
# sha :string(255)
# before_sha :string(255)
# push_data :text
# created_at :datetime
# updated_at :datetime
# tag :boolean default(FALSE)
# yaml_errors :text
# committed_at :datetime
# gl_project_id :integer
#
FactoryGirl
.
define
do
FactoryGirl
.
define
do
factory
:ci_empty_pipeline
,
class:
Ci
::
Pipeline
do
factory
:ci_empty_pipeline
,
class:
Ci
::
Pipeline
do
ref
'master'
ref
'master'
...
...
spec/requests/api/pipelines_spec.rb
0 → 100644
View file @
de7b8e51
require
'spec_helper'
describe
API
::
API
,
api:
true
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:non_member
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
end
before
do
project
.
team
<<
[
user
,
:master
]
end
describe
'GET /projects/:id/pipelines '
do
it_behaves_like
'a paginated resources'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/pipelines"
,
user
)
}
end
context
'authorized user'
do
it
'returns project pipelines'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'sha'
]).
to
match
/\A\h{40}\z/
end
end
context
'unauthorized user'
do
it
'does not return project pipelines'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines"
,
non_member
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'GET /projects/:id/pipelines/:pipeline_id'
do
context
'authorized user'
do
it
'returns project pipelines'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'sha'
]).
to
match
/\A\h{40}\z/
end
it
'returns 404 when it does not exist'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/123456"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'unauthorized user'
do
it
'should not return a project pipeline'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
"
,
non_member
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'POST /projects/:id/pipelines/:pipeline_id/retry'
do
context
'authorized user'
do
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
end
let!
(
:build
)
{
create
(
:ci_build
,
:failed
,
pipeline:
pipeline
)
}
it
'retries failed builds'
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/retry"
,
user
)
end
.
to
change
{
pipeline
.
builds
.
count
}.
from
(
1
).
to
(
2
)
expect
(
response
).
to
have_http_status
(
201
)
end
end
context
'unauthorized user'
do
it
'should not return a project pipeline'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/retry"
,
non_member
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'POST /projects/:id/pipelines/:pipeline_id/cancel'
do
let!
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
end
let!
(
:build
)
{
create
(
:ci_build
,
:running
,
pipeline:
pipeline
)
}
context
'authorized user'
do
it
'retries failed builds'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/cancel"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
'canceled'
)
end
end
context
'user without proper access rights'
do
let!
(
:reporter
)
{
create
(
:user
)
}
before
{
project
.
team
<<
[
reporter
,
:reporter
]
}
it
'rejects the action'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/cancel"
,
reporter
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
end
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