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
Jérome Perrin
gitlab-ce
Commits
549a2fa7
Commit
549a2fa7
authored
Jan 08, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify builds scope filtering in builds API
parent
a862ade5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
16 deletions
+39
-16
app/models/ci/build.rb
app/models/ci/build.rb
+4
-0
doc/api/builds.md
doc/api/builds.md
+2
-3
lib/api/builds.rb
lib/api/builds.rb
+19
-12
spec/requests/api/builds_spec.rb
spec/requests/api/builds_spec.rb
+14
-1
No files found.
app/models/ci/build.rb
View file @
549a2fa7
...
@@ -94,6 +94,10 @@ module Ci
...
@@ -94,6 +94,10 @@ module Ci
new_build
.
save
new_build
.
save
new_build
new_build
end
end
def
available_statuses
state_machines
[
:status
].
states
.
map
&
:value
end
end
end
state_machine
:status
,
initial: :pending
do
state_machine
:status
,
initial: :pending
do
...
...
doc/api/builds.md
View file @
549a2fa7
...
@@ -11,7 +11,7 @@ GET /projects/:id/builds
...
@@ -11,7 +11,7 @@ GET /projects/:id/builds
Parameters:
Parameters:
-
`id`
(required) - The ID of a project
-
`id`
(required) - The ID of a project
-
`scope`
(optional) - The scope of builds to show (one o
f:
`all`
,
`finished`
,
`running`
; default:
`all`
)
-
`scope`
(optional) - The scope of builds to show (one o
r array of: pending, running, failed, success, canceled; if none provided showing all builds
)
```
json
```
json
[
[
...
@@ -64,8 +64,7 @@ Parameters:
...
@@ -64,8 +64,7 @@ Parameters:
-
`id`
(required) - The ID of a project
-
`id`
(required) - The ID of a project
-
`sha`
(required) - The SHA id of a commit
-
`sha`
(required) - The SHA id of a commit
-
`scope`
(optional) - The scope of builds to show (one of:
`all`
,
`finished`
,
`running`
; default:
`all`
)
-
`scope`
(optional) - The scope of builds to show (one or array of: pending, running, failed, success, canceled; if none provided showing all builds)
```
json
```
json
[
[
...
...
lib/api/builds.rb
View file @
549a2fa7
...
@@ -8,9 +8,8 @@ module API
...
@@ -8,9 +8,8 @@ module API
#
#
# Parameters:
# Parameters:
# id (required) - The ID of a project
# id (required) - The ID of a project
# scope (optional) - The scope of builds to show (one of: all, finished, running; default: all)
# scope (optional) - The scope of builds to show (one or array of: pending, running, failed, success, canceled;
# page (optional) - The page number for pagination
# if none provided showing all builds)
# per_page (ooptional) - The value of items per page to show
# Example Request:
# Example Request:
# GET /projects/:id/builds
# GET /projects/:id/builds
get
':id/builds'
do
get
':id/builds'
do
...
@@ -24,7 +23,8 @@ module API
...
@@ -24,7 +23,8 @@ module API
# Parameters:
# Parameters:
# id (required) - The ID of a project
# id (required) - The ID of a project
# sha (required) - The SHA id of a commit
# sha (required) - The SHA id of a commit
# scope (optional) - The scope of builds to show (one of: all, finished, running; default: all)
# scope (optional) - The scope of builds to show (one or array of: pending, running, failed, success, canceled;
# if none provided showing all builds)
# Example Request:
# Example Request:
# GET /projects/:id/builds/commit/:sha
# GET /projects/:id/builds/commit/:sha
get
':id/builds/commit/:sha'
do
get
':id/builds/commit/:sha'
do
...
@@ -112,14 +112,21 @@ module API
...
@@ -112,14 +112,21 @@ module API
end
end
def
filter_builds
(
builds
,
scope
)
def
filter_builds
(
builds
,
scope
)
case
scope
available_scopes
=
Ci
::
Build
.
available_statuses
when
'finished'
scope
=
builds
.
finished
if
scope
.
is_a?
(
String
)
||
scope
.
is_a?
(
Symbol
)
when
'running'
available_scopes
&
[
scope
.
to_s
]
builds
.
running
elsif
scope
.
is_a?
(
Array
)
else
available_scopes
&
scope
builds
elsif
scope
.
respond_to?
(
:to_h
)
end
available_scopes
&
scope
.
to_h
.
values
else
[]
end
return
builds
if
scope
.
empty?
builds
.
where
(
status:
scope
)
end
end
def
authorize_manage_builds!
def
authorize_manage_builds!
...
...
spec/requests/api/builds_spec.rb
View file @
549a2fa7
...
@@ -18,7 +18,20 @@ describe API::API, api: true do
...
@@ -18,7 +18,20 @@ describe API::API, api: true do
it
'should return project builds'
do
it
'should return project builds'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/builds"
,
user
)
puts
json_response
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
end
it
'should filter project with one scope element'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds?scope=pending"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
end
it
'should filter project with array of scope elements'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds?scope[0]=pending&scope[1]=running"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_an
Array
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