summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-03 01:48:51 -0700
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-09-03 01:48:51 -0700
commitcc03600b22342a541ab1b4617eaf4d38d6d2d1da (patch)
tree5e497240ebd41b8a148173b11aa1c8b9ee57ba16
parent6ec909cfd038c8b6510d14144b28425c599fc1bd (diff)
parent2bd1682ab469687f0dce719f1417c9b03fa3a8db (diff)
downloadgitlab-ce-cc03600b22342a541ab1b4617eaf4d38d6d2d1da.tar.gz
Merge pull request #1347 from AlexDenisov/api_project_creation
API for new project creation
-rw-r--r--doc/api/projects.md18
-rw-r--r--lib/api/projects.rb21
-rw-r--r--spec/requests/api/projects_spec.rb37
3 files changed, 76 insertions, 0 deletions
diff --git a/doc/api/projects.md b/doc/api/projects.md
index d680b5d8597..b0c1e65709c 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -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.
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index eb23641c605..f42849cd2f2 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -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:
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 0cbc12af53b..cc6843ccb66 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -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)