summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorSebastian Ziebell <sebastian.ziebell@asquera.de>2013-03-07 14:51:56 +0100
committerSebastian Ziebell <sebastian.ziebell@asquera.de>2013-03-07 14:51:56 +0100
commit3374027e3a4e4eb040e59294a9ced9d7886a71e2 (patch)
tree4587984396a32047a6337e7810a39633ba683545 /lib/api
parent39114d259c6e4bd5bb60b18f561d06cc24e8c852 (diff)
parent9c2a6e201388e7e30987a8679ddfa65b9422a38c (diff)
downloadgitlab-ce-3374027e3a4e4eb040e59294a9ced9d7886a71e2.tar.gz
Merge branch 'master' into fixes/api, code clean up and tests fixed
Conflicts: doc/api/projects.md spec/requests/api/projects_spec.rb
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/groups.rb18
-rw-r--r--lib/api/merge_requests.rb2
-rw-r--r--lib/api/projects.rb75
-rw-r--r--lib/api/system_hooks.rb60
-rw-r--r--lib/api/users.rb20
5 files changed, 175 insertions, 0 deletions
diff --git a/lib/api/groups.rb b/lib/api/groups.rb
index 5aaa5eb4f54..beb615195a8 100644
--- a/lib/api/groups.rb
+++ b/lib/api/groups.rb
@@ -56,6 +56,24 @@ module Gitlab
not_found!
end
end
+
+ # Transfer a project to the Group namespace
+ #
+ # Parameters:
+ # id - group id
+ # project_id - project id
+ # Example Request:
+ # POST /groups/:id/projects/:project_id
+ post ":id/projects/:project_id" do
+ authenticated_as_admin!
+ @group = Group.find(params[:id])
+ project = Project.find(params[:project_id])
+ if project.transfer(@group)
+ present @group
+ else
+ not_found!
+ end
+ end
end
end
end
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 5adf57b36c5..234a005a998 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -8,6 +8,8 @@ module Gitlab
def handle_merge_request_errors!(errors)
if errors[:project_access].any?
error!(errors[:project_access], 422)
+ elsif errors[:branch_conflict].any?
+ error!(errors[:branch_conflict], 422)
end
not_found!
end
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index b8efef318d3..b1d6357fbbb 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -64,6 +64,38 @@ module Gitlab
end
end
+ # Create new project for a specified user. Only available to admin users.
+ #
+ # Parameters:
+ # user_id (required) - The ID of a user
+ # name (required) - name for new project
+ # description (optional) - short project description
+ # default_branch (optional) - 'master' by default
+ # issues_enabled (optional) - enabled by default
+ # wall_enabled (optional) - enabled by default
+ # merge_requests_enabled (optional) - enabled by default
+ # wiki_enabled (optional) - enabled by default
+ # Example Request
+ # POST /projects/user/:user_id
+ post "user/:user_id" do
+ authenticated_as_admin!
+ user = User.find(params[:user_id])
+ attrs = attributes_for_keys [:name,
+ :description,
+ :default_branch,
+ :issues_enabled,
+ :wall_enabled,
+ :merge_requests_enabled,
+ :wiki_enabled]
+ @project = ::Projects::CreateContext.new(user, attrs).execute
+ if @project.saved?
+ present @project, with: Entities::Project
+ else
+ not_found!
+ end
+ end
+
+
# Get a project team members
#
# Parameters:
@@ -471,6 +503,49 @@ module Gitlab
present tree.data
end
+ # Get a specific project's keys
+ #
+ # Example Request:
+ # GET /projects/:id/keys
+ get ":id/keys" do
+ present user_project.deploy_keys, with: Entities::SSHKey
+ end
+
+ # Get single key owned by currently authenticated user
+ #
+ # Example Request:
+ # GET /projects/:id/keys/:id
+ get ":id/keys/:key_id" do
+ key = user_project.deploy_keys.find params[:key_id]
+ present key, with: Entities::SSHKey
+ end
+
+ # Add new ssh key to currently authenticated user
+ #
+ # Parameters:
+ # key (required) - New SSH Key
+ # title (required) - New SSH Key's title
+ # Example Request:
+ # POST /projects/:id/keys
+ post ":id/keys" do
+ attrs = attributes_for_keys [:title, :key]
+ key = user_project.deploy_keys.new attrs
+ if key.save
+ present key, with: Entities::SSHKey
+ else
+ not_found!
+ end
+ end
+
+ # Delete existed ssh key of currently authenticated user
+ #
+ # Example Request:
+ # DELETE /projects/:id/keys/:id
+ delete ":id/keys/:key_id" do
+ key = user_project.deploy_keys.find params[:key_id]
+ key.delete
+ end
+
end
end
end
diff --git a/lib/api/system_hooks.rb b/lib/api/system_hooks.rb
new file mode 100644
index 00000000000..665a1cdd0d2
--- /dev/null
+++ b/lib/api/system_hooks.rb
@@ -0,0 +1,60 @@
+module Gitlab
+ # Hooks API
+ class SystemHooks < Grape::API
+ before { authenticated_as_admin! }
+
+ resource :hooks do
+ # Get the list of system hooks
+ #
+ # Example Request:
+ # GET /hooks
+ get do
+ @hooks = SystemHook.all
+ present @hooks, with: Entities::Hook
+ end
+
+ # Create new system hook
+ #
+ # Parameters:
+ # url (required) - url for system hook
+ # Example Request
+ # POST /hooks
+ post do
+ attrs = attributes_for_keys [:url]
+ @hook = SystemHook.new attrs
+ if @hook.save
+ present @hook, with: Entities::Hook
+ else
+ not_found!
+ end
+ end
+
+ # Test a hook
+ #
+ # Example Request
+ # GET /hooks/:id
+ get ":id" do
+ @hook = SystemHook.find(params[:id])
+ data = {
+ event_name: "project_create",
+ name: "Ruby",
+ path: "ruby",
+ project_id: 1,
+ owner_name: "Someone",
+ owner_email: "example@gitlabhq.com"
+ }
+ @hook.execute(data)
+ data
+ end
+
+ # Delete a hook
+ #
+ # Example Request:
+ # DELETE /hooks/:id
+ delete ":id" do
+ @hook = SystemHook.find(params[:id])
+ @hook.destroy
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/lib/api/users.rb b/lib/api/users.rb
index 5e0680de71a..6cc3a7e52c9 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -81,6 +81,26 @@ module Gitlab
end
end
+ # Add ssh key to a specified user. Only available to admin users.
+ #
+ # Parameters:
+ # id (required) - The ID of a user
+ # key (required) - New SSH Key
+ # title (required) - New SSH Key's title
+ # Example Request:
+ # POST /users/:id/keys
+ post ":id/keys" do
+ authenticated_as_admin!
+ user = User.find(params[:id])
+ attrs = attributes_for_keys [:title, :key]
+ key = user.keys.new attrs
+ if key.save
+ present key, with: Entities::SSHKey
+ else
+ not_found!
+ end
+ end
+
# Delete user. Available only for admin
#
# Example Request: