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
7c607a55
Commit
7c607a55
authored
Nov 09, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grapify the projects API
parent
c5482796
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
288 additions
and
358 deletions
+288
-358
doc/api/projects.md
doc/api/projects.md
+1
-0
lib/api/helpers.rb
lib/api/helpers.rb
+2
-24
lib/api/projects.rb
lib/api/projects.rb
+265
-313
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+20
-21
No files found.
doc/api/projects.md
View file @
7c607a55
...
@@ -626,6 +626,7 @@ Parameters:
...
@@ -626,6 +626,7 @@ Parameters:
|
`path`
| string | no | Custom repository name for new project. By default generated based on name |
|
`path`
| string | no | Custom repository name for new project. By default generated based on name |
|
`default_branch`
| string | no |
`master`
by default |
|
`default_branch`
| string | no |
`master`
by default |
|
`namespace_id`
| integer | no | Namespace for the new project (defaults to the current user's namespace) |
|
`namespace_id`
| integer | no | Namespace for the new project (defaults to the current user's namespace) |
|
`default_branch`
| string | no |
`master`
by default |
|
`description`
| string | no | Short project description |
|
`description`
| string | no | Short project description |
|
`issues_enabled`
| boolean | no | Enable issues for this project |
|
`issues_enabled`
| boolean | no | Enable issues for this project |
|
`merge_requests_enabled`
| boolean | no | Enable merge requests for this project |
|
`merge_requests_enabled`
| boolean | no | Enable merge requests for this project |
...
...
lib/api/helpers.rb
View file @
7c607a55
...
@@ -324,11 +324,6 @@ module API
...
@@ -324,11 +324,6 @@ module API
# Projects helpers
# Projects helpers
def
filter_projects
(
projects
)
def
filter_projects
(
projects
)
# If the archived parameter is passed, limit results accordingly
if
params
[
:archived
].
present?
projects
=
projects
.
where
(
archived:
to_boolean
(
params
[
:archived
]))
end
if
params
[
:search
].
present?
if
params
[
:search
].
present?
projects
=
projects
.
search
(
params
[
:search
])
projects
=
projects
.
search
(
params
[
:search
])
end
end
...
@@ -337,25 +332,8 @@ module API
...
@@ -337,25 +332,8 @@ module API
projects
=
projects
.
search_by_visibility
(
params
[
:visibility
])
projects
=
projects
.
search_by_visibility
(
params
[
:visibility
])
end
end
projects
.
reorder
(
project_order_by
=>
project_sort
)
projects
=
projects
.
where
(
archived:
params
[
:archived
])
end
projects
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
def
project_order_by
order_fields
=
%w(id name path created_at updated_at last_activity_at)
if
order_fields
.
include?
(
params
[
'order_by'
])
params
[
'order_by'
]
else
'created_at'
end
end
def
project_sort
if
params
[
"sort"
]
==
'asc'
:asc
else
:desc
end
end
end
# file helpers
# file helpers
...
...
lib/api/projects.rb
View file @
7c607a55
This diff is collapsed.
Click to expand it.
spec/requests/api/projects_spec.rb
View file @
7c607a55
...
@@ -415,16 +415,7 @@ describe API::API, api: true do
...
@@ -415,16 +415,7 @@ describe API::API, api: true do
not_to
change
{
Project
.
count
}
not_to
change
{
Project
.
count
}
expect
(
response
).
to
have_http_status
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'name'
]).
to
eq
([
expect
(
json_response
[
'error'
]).
to
eq
(
'name is missing'
)
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
,
Gitlab
::
Regex
.
project_name_regex_message
])
expect
(
json_response
[
'message'
][
'path'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
,
Gitlab
::
Regex
.
send
(
:project_path_regex_message
)
])
end
end
it
'assigns attributes to project'
do
it
'assigns attributes to project'
do
...
@@ -438,6 +429,7 @@ describe API::API, api: true do
...
@@ -438,6 +429,7 @@ describe API::API, api: true do
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
expect
(
response
).
to
have_http_status
(
201
)
project
.
each_pair
do
|
k
,
v
|
project
.
each_pair
do
|
k
,
v
|
next
if
%i[has_external_issue_tracker path]
.
include?
(
k
)
next
if
%i[has_external_issue_tracker path]
.
include?
(
k
)
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
...
@@ -447,6 +439,8 @@ describe API::API, api: true do
...
@@ -447,6 +439,8 @@ describe API::API, api: true do
it
'sets a project as public'
do
it
'sets a project as public'
do
project
=
attributes_for
(
:project
,
:public
)
project
=
attributes_for
(
:project
,
:public
)
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'public'
]).
to
be_truthy
expect
(
json_response
[
'public'
]).
to
be_truthy
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
PUBLIC
)
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
PUBLIC
)
end
end
...
@@ -454,6 +448,8 @@ describe API::API, api: true do
...
@@ -454,6 +448,8 @@ describe API::API, api: true do
it
'sets a project as public using :public'
do
it
'sets a project as public using :public'
do
project
=
attributes_for
(
:project
,
{
public:
true
})
project
=
attributes_for
(
:project
,
{
public:
true
})
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'public'
]).
to
be_truthy
expect
(
json_response
[
'public'
]).
to
be_truthy
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
PUBLIC
)
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
PUBLIC
)
end
end
...
@@ -461,6 +457,8 @@ describe API::API, api: true do
...
@@ -461,6 +457,8 @@ describe API::API, api: true do
it
'sets a project as internal'
do
it
'sets a project as internal'
do
project
=
attributes_for
(
:project
,
:internal
)
project
=
attributes_for
(
:project
,
:internal
)
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'public'
]).
to
be_falsey
expect
(
json_response
[
'public'
]).
to
be_falsey
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
INTERNAL
)
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
INTERNAL
)
end
end
...
@@ -468,6 +466,7 @@ describe API::API, api: true do
...
@@ -468,6 +466,7 @@ describe API::API, api: true do
it
'sets a project as internal overriding :public'
do
it
'sets a project as internal overriding :public'
do
project
=
attributes_for
(
:project
,
:internal
,
{
public:
true
})
project
=
attributes_for
(
:project
,
:internal
,
{
public:
true
})
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
project
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'public'
]).
to
be_falsey
expect
(
json_response
[
'public'
]).
to
be_falsey
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
INTERNAL
)
expect
(
json_response
[
'visibility_level'
]).
to
eq
(
Gitlab
::
VisibilityLevel
::
INTERNAL
)
end
end
...
@@ -848,7 +847,7 @@ describe API::API, api: true do
...
@@ -848,7 +847,7 @@ describe API::API, api: true do
it
'is idempotent if not forked'
do
it
'is idempotent if not forked'
do
expect
(
project_fork_target
.
forked_from_project
).
to
be_nil
expect
(
project_fork_target
.
forked_from_project
).
to
be_nil
delete
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork"
,
admin
)
delete
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork"
,
admin
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
304
)
expect
(
project_fork_target
.
reload
.
forked_from_project
).
to
be_nil
expect
(
project_fork_target
.
reload
.
forked_from_project
).
to
be_nil
end
end
end
end
...
@@ -865,7 +864,7 @@ describe API::API, api: true do
...
@@ -865,7 +864,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
,
expires_at:
expires_at
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
,
expires_at:
expires_at
end
.
to
change
{
ProjectGroupLink
.
count
}.
by
(
1
)
end
.
to
change
{
ProjectGroupLink
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
201
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'group_id'
]).
to
eq
(
group
.
id
)
expect
(
json_response
[
'group_id'
]).
to
eq
(
group
.
id
)
expect
(
json_response
[
'group_access'
]).
to
eq
(
Gitlab
::
Access
::
DEVELOPER
)
expect
(
json_response
[
'group_access'
]).
to
eq
(
Gitlab
::
Access
::
DEVELOPER
)
expect
(
json_response
[
'expires_at'
]).
to
eq
(
expires_at
.
to_s
)
expect
(
json_response
[
'expires_at'
]).
to
eq
(
expires_at
.
to_s
)
...
@@ -873,18 +872,18 @@ describe API::API, api: true do
...
@@ -873,18 +872,18 @@ describe API::API, api: true do
it
"returns a 400 error when group id is not given"
do
it
"returns a 400 error when group id is not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_access:
Gitlab
::
Access
::
DEVELOPER
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_access:
Gitlab
::
Access
::
DEVELOPER
expect
(
response
.
status
).
to
eq
400
expect
(
response
).
to
have_http_status
(
400
)
end
end
it
"returns a 400 error when access level is not given"
do
it
"returns a 400 error when access level is not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
expect
(
response
.
status
).
to
eq
400
expect
(
response
).
to
have_http_status
(
400
)
end
end
it
"returns a 400 error when sharing is disabled"
do
it
"returns a 400 error when sharing is disabled"
do
project
.
namespace
.
update
(
share_with_group_lock:
true
)
project
.
namespace
.
update
(
share_with_group_lock:
true
)
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
expect
(
response
.
status
).
to
eq
400
expect
(
response
).
to
have_http_status
(
400
)
end
end
it
'returns a 404 error when user cannot read group'
do
it
'returns a 404 error when user cannot read group'
do
...
@@ -892,19 +891,20 @@ describe API::API, api: true do
...
@@ -892,19 +891,20 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
private_group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
private_group
.
id
,
group_access:
Gitlab
::
Access
::
DEVELOPER
expect
(
response
.
status
).
to
eq
404
expect
(
response
).
to
have_http_status
(
404
)
end
end
it
'returns a 404 error when group does not exist'
do
it
'returns a 404 error when group does not exist'
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
1234
,
group_access:
Gitlab
::
Access
::
DEVELOPER
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
1234
,
group_access:
Gitlab
::
Access
::
DEVELOPER
expect
(
response
.
status
).
to
eq
404
expect
(
response
).
to
have_http_status
(
404
)
end
end
it
"returns a 40
9
error when wrong params passed"
do
it
"returns a 40
0
error when wrong params passed"
do
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
1234
post
api
(
"/projects/
#{
project
.
id
}
/share"
,
user
),
group_id:
group
.
id
,
group_access:
1234
expect
(
response
.
status
).
to
eq
409
expect
(
json_response
[
'message'
]).
to
eq
'Group access is not included in the list'
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
'group_access does not have a valid value'
end
end
end
end
...
@@ -1017,7 +1017,6 @@ describe API::API, api: true do
...
@@ -1017,7 +1017,6 @@ describe API::API, api: true do
it
'updates visibility_level from public to private'
do
it
'updates visibility_level from public to private'
do
project3
.
update_attributes
({
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
})
project3
.
update_attributes
({
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
})
project_param
=
{
public:
false
}
project_param
=
{
public:
false
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user
),
project_param
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user
),
project_param
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
...
...
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