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
Boxiang Sun
gitlab-ce
Commits
97338496
Commit
97338496
authored
Jan 13, 2016
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some fixes after review
parent
ab2c6cc0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
51 deletions
+21
-51
doc/api/builds.md
doc/api/builds.md
+0
-36
lib/api/builds.rb
lib/api/builds.rb
+13
-11
lib/api/entities.rb
lib/api/entities.rb
+2
-4
spec/requests/api/builds_spec.rb
spec/requests/api/builds_spec.rb
+6
-0
No files found.
doc/api/builds.md
View file @
97338496
...
@@ -40,23 +40,14 @@ Parameters:
...
@@ -40,23 +40,14 @@ Parameters:
"user"
:
{
"user"
:
{
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"bio"
:
null
,
"bio"
:
null
,
"can_create_group"
:
true
,
"can_create_project"
:
true
,
"color_scheme_id"
:
2
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"current_sign_in_at"
:
"2016-01-11T09:31:40.472Z"
,
"email"
:
"admin@example.com"
,
"id"
:
1
,
"id"
:
1
,
"identities"
:
[],
"is_admin"
:
true
,
"is_admin"
:
true
,
"linkedin"
:
""
,
"linkedin"
:
""
,
"name"
:
"Administrator"
,
"name"
:
"Administrator"
,
"projects_limit"
:
100
,
"skype"
:
""
,
"skype"
:
""
,
"state"
:
"active"
,
"state"
:
"active"
,
"theme_id"
:
3
,
"twitter"
:
""
,
"twitter"
:
""
,
"two_factor_enabled"
:
false
,
"username"
:
"root"
,
"username"
:
"root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"website_url"
:
""
"website_url"
:
""
...
@@ -87,23 +78,14 @@ Parameters:
...
@@ -87,23 +78,14 @@ Parameters:
"user"
:
{
"user"
:
{
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"bio"
:
null
,
"bio"
:
null
,
"can_create_group"
:
true
,
"can_create_project"
:
true
,
"color_scheme_id"
:
2
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"current_sign_in_at"
:
"2016-01-11T09:31:40.472Z"
,
"email"
:
"admin@example.com"
,
"id"
:
1
,
"id"
:
1
,
"identities"
:
[],
"is_admin"
:
true
,
"is_admin"
:
true
,
"linkedin"
:
""
,
"linkedin"
:
""
,
"name"
:
"Administrator"
,
"name"
:
"Administrator"
,
"projects_limit"
:
100
,
"skype"
:
""
,
"skype"
:
""
,
"state"
:
"active"
,
"state"
:
"active"
,
"theme_id"
:
3
,
"twitter"
:
""
,
"twitter"
:
""
,
"two_factor_enabled"
:
false
,
"username"
:
"root"
,
"username"
:
"root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"website_url"
:
""
"website_url"
:
""
...
@@ -177,23 +159,14 @@ Parameters:
...
@@ -177,23 +159,14 @@ Parameters:
"user"
:
{
"user"
:
{
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"bio"
:
null
,
"bio"
:
null
,
"can_create_group"
:
true
,
"can_create_project"
:
true
,
"color_scheme_id"
:
2
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"current_sign_in_at"
:
"2016-01-12T10:30:48.315Z"
,
"email"
:
"admin@example.com"
,
"id"
:
1
,
"id"
:
1
,
"identities"
:
[],
"is_admin"
:
true
,
"is_admin"
:
true
,
"linkedin"
:
""
,
"linkedin"
:
""
,
"name"
:
"Administrator"
,
"name"
:
"Administrator"
,
"projects_limit"
:
100
,
"skype"
:
""
,
"skype"
:
""
,
"state"
:
"active"
,
"state"
:
"active"
,
"theme_id"
:
3
,
"twitter"
:
""
,
"twitter"
:
""
,
"two_factor_enabled"
:
false
,
"username"
:
"root"
,
"username"
:
"root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"website_url"
:
""
"website_url"
:
""
...
@@ -241,23 +214,14 @@ Parameters:
...
@@ -241,23 +214,14 @@ Parameters:
"user"
:
{
"user"
:
{
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"bio"
:
null
,
"bio"
:
null
,
"can_create_group"
:
true
,
"can_create_project"
:
true
,
"color_scheme_id"
:
2
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
"current_sign_in_at"
:
"2016-01-11T09:31:40.472Z"
,
"email"
:
"admin@example.com"
,
"id"
:
1
,
"id"
:
1
,
"identities"
:
[],
"is_admin"
:
true
,
"is_admin"
:
true
,
"linkedin"
:
""
,
"linkedin"
:
""
,
"name"
:
"Administrator"
,
"name"
:
"Administrator"
,
"projects_limit"
:
100
,
"skype"
:
""
,
"skype"
:
""
,
"state"
:
"active"
,
"state"
:
"active"
,
"theme_id"
:
3
,
"twitter"
:
""
,
"twitter"
:
""
,
"two_factor_enabled"
:
false
,
"username"
:
"root"
,
"username"
:
"root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"web_url"
:
"http://gitlab.dev/u/root"
,
"website_url"
:
""
"website_url"
:
""
...
...
lib/api/builds.rb
View file @
97338496
...
@@ -35,6 +35,7 @@ module API
...
@@ -35,6 +35,7 @@ module API
builds
=
commit
.
builds
.
order
(
'id DESC'
)
builds
=
commit
.
builds
.
order
(
'id DESC'
)
builds
=
filter_builds
(
builds
,
params
[
:scope
])
builds
=
filter_builds
(
builds
,
params
[
:scope
])
present
paginate
(
builds
),
with:
Entities
::
Build
,
present
paginate
(
builds
),
with:
Entities
::
Build
,
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
...
@@ -118,25 +119,26 @@ module API
...
@@ -118,25 +119,26 @@ module API
helpers
do
helpers
do
def
get_build
(
id
)
def
get_build
(
id
)
user_project
.
builds
.
where
(
id:
id
).
first
user_project
.
builds
.
find_by
(
id:
id
.
to_i
)
end
end
def
filter_builds
(
builds
,
scope
)
def
filter_builds
(
builds
,
scope
)
available_scopes
=
Ci
::
Build
.
available_statuses
return
builds
if
scope
.
nil?
||
scope
.
empty?
available_statuses
=
Ci
::
Build
.
available_statuses
scope
=
scope
=
if
scope
.
is_a?
(
String
)
||
scope
.
is_a?
(
Symbol
)
if
scope
.
is_a?
(
String
)
available_scopes
&
[
scope
.
to_s
]
[
scope
]
elsif
scope
.
is_a?
(
Array
)
elsif
scope
.
is_a?
(
Hashie
::
Mash
)
available_scopes
&
scope
scope
.
values
elsif
scope
.
respond_to?
(
:to_h
)
available_scopes
&
scope
.
to_h
.
values
else
else
[]
[
'unknown'
]
end
end
return
builds
if
scope
.
empty?
unknown
=
scope
-
available_statuses
render_api_error!
(
'Scope contains invalid value(s)'
,
400
)
unless
unknown
.
empty?
builds
.
where
(
status:
scope
)
builds
.
where
(
status:
available_statuses
&&
scope
)
end
end
def
authorize_manage_builds!
def
authorize_manage_builds!
...
...
lib/api/entities.rb
View file @
97338496
...
@@ -378,18 +378,16 @@ module API
...
@@ -378,18 +378,16 @@ module API
expose
:id
,
:status
,
:stage
,
:name
,
:ref
,
:tag
,
:coverage
expose
:id
,
:status
,
:stage
,
:name
,
:ref
,
:tag
,
:coverage
expose
:created_at
,
:started_at
,
:finished_at
expose
:created_at
,
:started_at
,
:finished_at
expose
:user
,
with:
User
expose
:user
,
with:
User
# TODO: download_url in Ci:Build model is an GitLab Web Interface URL, not API URL. We should think on some API
# for downloading of artifacts (see: https://gitlab.com/gitlab-org/gitlab-ce/issues/4255)
expose
:download_url
do
|
repo_obj
,
options
|
expose
:download_url
do
|
repo_obj
,
options
|
if
options
[
:user_can_download_artifacts
]
if
options
[
:user_can_download_artifacts
]
repo_obj
.
download_url
repo_obj
.
download_url
else
nil
end
end
end
end
expose
:commit
,
with:
RepoCommit
do
|
repo_obj
,
_options
|
expose
:commit
,
with:
RepoCommit
do
|
repo_obj
,
_options
|
if
repo_obj
.
respond_to?
(
:commit
)
if
repo_obj
.
respond_to?
(
:commit
)
repo_obj
.
commit
.
commit_data
repo_obj
.
commit
.
commit_data
else
nil
end
end
end
end
expose
:runner
,
with:
Runner
expose
:runner
,
with:
Runner
...
...
spec/requests/api/builds_spec.rb
View file @
97338496
...
@@ -35,6 +35,12 @@ describe API::API, api: true do
...
@@ -35,6 +35,12 @@ describe API::API, api: true do
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
it
'should respond 400 when scope contains invalid state'
do
get
api
(
"/projects/
#{
project
.
id
}
/builds?scope[0]=pending&scope[1]=unknown_status"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
end
end
end
context
'unauthorized user'
do
context
'unauthorized user'
do
...
...
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