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
cc03600b
Commit
cc03600b
authored
Sep 03, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1347 from AlexDenisov/api_project_creation
API for new project creation
parents
6ec909cf
2bd1682a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
+76
-0
doc/api/projects.md
doc/api/projects.md
+18
-0
lib/api/projects.rb
lib/api/projects.rb
+21
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+37
-0
No files found.
doc/api/projects.md
View file @
cc03600b
...
...
@@ -89,6 +89,24 @@ Parameters:
}
```
## Create project
Create new project owned by user
```
POST /projects
```
Parameters:
+
`name`
(required) - new project name
+
`code`
(optional) - new project code, uses project name if not set
+
`path`
(optional) - new project path, uses project name if not set
Will return created project with status
`201 Created`
on success, or
`404 Not
found`
on fail.
## Project repository branches
Get a list of project repository branches sorted by name alphabetically.
...
...
lib/api/projects.rb
View file @
cc03600b
...
...
@@ -23,6 +23,27 @@ module Gitlab
present
user_project
,
with:
Entities
::
Project
end
# Create new project
#
# Parameters:
# name (required) - name for new project
# code (optional) - code for new project, uses project name if not set
# path (optional) - path for new project, uses project name if not set
# Example Request
# POST /projects
post
do
project
=
{}
project
[
:name
]
=
params
[
:name
]
project
[
:code
]
=
params
[
:code
]
||
project
[
:name
]
project
[
:path
]
=
params
[
:path
]
||
project
[
:name
]
@project
=
Project
.
create_by_user
(
project
,
current_user
)
if
@project
.
saved?
present
@project
,
with:
Entities
::
Project
else
error!
({
'message'
=>
'404 Not found'
},
404
)
end
end
# Get a project repository branches
#
# Parameters:
...
...
spec/requests/api/projects_spec.rb
View file @
cc03600b
...
...
@@ -25,6 +25,43 @@ describe Gitlab::API do
end
end
describe
"POST /projects"
do
it
"should create new project without code and path"
do
lambda
{
name
=
"foo"
post
api
(
"/projects"
,
user
),
{
name:
name
}
response
.
status
.
should
==
201
json_response
[
"name"
].
should
==
name
json_response
[
"code"
].
should
==
name
json_response
[
"path"
].
should
==
name
}.
should
change
{
Project
.
count
}.
by
(
1
)
end
it
"should create new project"
do
lambda
{
name
=
"foo"
path
=
"bar"
code
=
"bazz"
post
api
(
"/projects"
,
user
),
{
code:
code
,
path:
path
,
name:
name
}
response
.
status
.
should
==
201
json_response
[
"name"
].
should
==
name
json_response
[
"path"
].
should
==
path
json_response
[
"code"
].
should
==
code
}.
should
change
{
Project
.
count
}.
by
(
1
)
end
it
"should not create project without name"
do
lambda
{
post
api
(
"/projects"
,
user
)
response
.
status
.
should
==
404
}.
should_not
change
{
Project
.
count
}
end
end
describe
"GET /projects/:id"
do
it
"should return a project by id"
do
get
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
...
...
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