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
Tatuya Kamada
gitlab-ce
Commits
8f527cbf
Commit
8f527cbf
authored
Oct 24, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grapify builds API
parent
9af0dd5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
83 deletions
+79
-83
lib/api/builds.rb
lib/api/builds.rb
+79
-83
No files found.
lib/api/builds.rb
View file @
8f527cbf
...
@@ -3,15 +3,32 @@ module API
...
@@ -3,15 +3,32 @@ module API
class
Builds
<
Grape
::
API
class
Builds
<
Grape
::
API
before
{
authenticate!
}
before
{
authenticate!
}
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
do
# Get a project builds
helpers
do
#
params
:optional_scope
do
# Parameters:
optional
:scope
,
types:
[
String
,
Array
[
String
]],
desc:
'The scope of builds to show'
,
# id (required) - The ID of a project
values:
[
'pending'
,
'running'
,
'failed'
,
'success'
,
'canceled'
],
# scope (optional) - The scope of builds to show (one or array of: created, pending, running, failed, success, canceled, skipped;
coerce_with:
->
(
scope
)
{
# if none provided showing all builds)
if
scope
.
is_a?
(
String
)
# Example Request:
[
scope
]
# GET /projects/:id/builds
elsif
scope
.
is_a?
(
Hashie
::
Mash
)
scope
.
values
else
[
'unknown'
]
end
}
end
end
desc
'Get a project builds'
do
success
Entities
::
Build
end
params
do
use
:optional_scope
end
get
':id/builds'
do
get
':id/builds'
do
builds
=
user_project
.
builds
.
order
(
'id DESC'
)
builds
=
user_project
.
builds
.
order
(
'id DESC'
)
builds
=
filter_builds
(
builds
,
params
[
:scope
])
builds
=
filter_builds
(
builds
,
params
[
:scope
])
...
@@ -20,15 +37,13 @@ module API
...
@@ -20,15 +37,13 @@ module API
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
end
end
# Get builds for a specific commit of a project
desc
'Get builds for a specific commit of a project'
do
#
success
Entities
::
Build
# Parameters:
end
# id (required) - The ID of a project
params
do
# sha (required) - The SHA id of a commit
requires
:sha
,
type:
String
,
desc:
'The SHA id of a commit'
# scope (optional) - The scope of builds to show (one or array of: created, pending, running, failed, success, canceled, skipped;
use
:optional_scope
# if none provided showing all builds)
end
# Example Request:
# GET /projects/:id/repository/commits/:sha/builds
get
':id/repository/commits/:sha/builds'
do
get
':id/repository/commits/:sha/builds'
do
authorize_read_builds!
authorize_read_builds!
...
@@ -42,13 +57,12 @@ module API
...
@@ -42,13 +57,12 @@ module API
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
end
end
# Get a specific build of a project
desc
'Get a specific build of a project'
do
#
success
Entities
::
Build
# Parameters:
end
# id (required) - The ID of a project
params
do
# build_id (required) - The ID of a build
requires
:build_id
,
type:
Integer
,
desc:
'The ID of a build'
# Example Request:
end
# GET /projects/:id/builds/:build_id
get
':id/builds/:build_id'
do
get
':id/builds/:build_id'
do
authorize_read_builds!
authorize_read_builds!
...
@@ -58,13 +72,12 @@ module API
...
@@ -58,13 +72,12 @@ module API
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
end
end
# Download the artifacts file from build
desc
'Download the artifacts file from build'
do
#
detail
'This feature was introduced in GitLab 8.5'
# Parameters:
end
# id (required) - The ID of a build
params
do
# token (required) - The build authorization token
requires
:build_id
,
type:
Integer
,
desc:
'The ID of a build'
# Example Request:
end
# GET /projects/:id/builds/:build_id/artifacts
get
':id/builds/:build_id/artifacts'
do
get
':id/builds/:build_id/artifacts'
do
authorize_read_builds!
authorize_read_builds!
...
@@ -73,14 +86,13 @@ module API
...
@@ -73,14 +86,13 @@ module API
present_artifacts!
(
build
.
artifacts_file
)
present_artifacts!
(
build
.
artifacts_file
)
end
end
# Download the artifacts file from ref_name and job
desc
'Download the artifacts file from build'
do
#
detail
'This feature was introduced in GitLab 8.10'
# Parameters:
end
# id (required) - The ID of a project
params
do
# ref_name (required) - The ref from repository
requires
:ref_name
,
type:
String
,
desc:
'The ref from repository'
# job (required) - The name for the build
requires
:job
,
type:
String
,
desc:
'The name for the build'
# Example Request:
end
# GET /projects/:id/builds/artifacts/:ref_name/download?job=name
get
':id/builds/artifacts/:ref_name/download'
,
get
':id/builds/artifacts/:ref_name/download'
,
requirements:
{
ref_name:
/.+/
}
do
requirements:
{
ref_name:
/.+/
}
do
authorize_read_builds!
authorize_read_builds!
...
@@ -91,17 +103,13 @@ module API
...
@@ -91,17 +103,13 @@ module API
present_artifacts!
(
latest_build
.
artifacts_file
)
present_artifacts!
(
latest_build
.
artifacts_file
)
end
end
# Get a trace of a specific build of a project
#
# Parameters:
# id (required) - The ID of a project
# build_id (required) - The ID of a build
# Example Request:
# GET /projects/:id/build/:build_id/trace
#
# TODO: We should use `present_file!` and leave this implementation for backward compatibility (when build trace
# TODO: We should use `present_file!` and leave this implementation for backward compatibility (when build trace
# is saved in the DB instead of file). But before that, we need to consider how to replace the value of
# is saved in the DB instead of file). But before that, we need to consider how to replace the value of
# `runners_token` with some mask (like `xxxxxx`) when sending trace file directly by workhorse.
# `runners_token` with some mask (like `xxxxxx`) when sending trace file directly by workhorse.
desc
'Get a trace of a specific build of a project'
params
do
requires
:build_id
,
type:
Integer
,
desc:
'The ID of a build'
end
get
':id/builds/:build_id/trace'
do
get
':id/builds/:build_id/trace'
do
authorize_read_builds!
authorize_read_builds!
...
@@ -115,13 +123,12 @@ module API
...
@@ -115,13 +123,12 @@ module API
body
trace
body
trace
end
end
# Cancel a specific build of a project
desc
'Cancel a specific build of a project'
do
#
success
Entities
::
Build
# parameters:
end
# id (required) - the id of a project
params
do
# build_id (required) - the id of a build
requires
:build_id
,
type:
Integer
,
desc:
'The ID of a build'
# example request:
end
# post /projects/:id/build/:build_id/cancel
post
':id/builds/:build_id/cancel'
do
post
':id/builds/:build_id/cancel'
do
authorize_update_builds!
authorize_update_builds!
...
@@ -133,13 +140,12 @@ module API
...
@@ -133,13 +140,12 @@ module API
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
end
end
# Retry a specific build of a project
desc
'Retry a specific build of a project'
do
#
success
Entities
::
Build
# parameters:
end
# id (required) - the id of a project
params
do
# build_id (required) - the id of a build
requires
:build_id
,
type:
Integer
,
desc:
'The ID of a build'
# example request:
end
# post /projects/:id/build/:build_id/retry
post
':id/builds/:build_id/retry'
do
post
':id/builds/:build_id/retry'
do
authorize_update_builds!
authorize_update_builds!
...
@@ -152,13 +158,12 @@ module API
...
@@ -152,13 +158,12 @@ module API
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
user_can_download_artifacts:
can?
(
current_user
,
:read_build
,
user_project
)
end
end
# Erase build (remove artifacts and build trace)
desc
'Erase build (remove artifacts and build trace)'
do
#
success
Entities
::
Build
# Parameters:
end
# id (required) - the id of a project
params
do
# build_id (required) - the id of a build
requires
:build_id
,
type:
Integer
,
desc:
'The ID of a build'
# example Request:
end
# post /projects/:id/build/:build_id/erase
post
':id/builds/:build_id/erase'
do
post
':id/builds/:build_id/erase'
do
authorize_update_builds!
authorize_update_builds!
...
@@ -170,13 +175,12 @@ module API
...
@@ -170,13 +175,12 @@ module API
user_can_download_artifacts:
can?
(
current_user
,
:download_build_artifacts
,
user_project
)
user_can_download_artifacts:
can?
(
current_user
,
:download_build_artifacts
,
user_project
)
end
end
# Keep the artifacts to prevent them from being deleted
desc
'Keep the artifacts to prevent them from being deleted'
do
#
success
Entities
::
Build
# Parameters:
end
# id (required) - the id of a project
params
do
# build_id (required) - The ID of a build
requires
:build_id
,
type:
Integer
,
desc:
'The ID of a build'
# Example Request:
end
# POST /projects/:id/builds/:build_id/artifacts/keep
post
':id/builds/:build_id/artifacts/keep'
do
post
':id/builds/:build_id/artifacts/keep'
do
authorize_update_builds!
authorize_update_builds!
...
@@ -235,14 +239,6 @@ module API
...
@@ -235,14 +239,6 @@ module API
return
builds
if
scope
.
nil?
||
scope
.
empty?
return
builds
if
scope
.
nil?
||
scope
.
empty?
available_statuses
=
::
CommitStatus
::
AVAILABLE_STATUSES
available_statuses
=
::
CommitStatus
::
AVAILABLE_STATUSES
scope
=
if
scope
.
is_a?
(
String
)
[
scope
]
elsif
scope
.
is_a?
(
Hashie
::
Mash
)
scope
.
values
else
[
'unknown'
]
end
unknown
=
scope
-
available_statuses
unknown
=
scope
-
available_statuses
render_api_error!
(
'Scope contains invalid value(s)'
,
400
)
unless
unknown
.
empty?
render_api_error!
(
'Scope contains invalid value(s)'
,
400
)
unless
unknown
.
empty?
...
...
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