diff options
author | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-03-07 14:51:56 +0100 |
---|---|---|
committer | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-03-07 14:51:56 +0100 |
commit | 3374027e3a4e4eb040e59294a9ced9d7886a71e2 (patch) | |
tree | 4587984396a32047a6337e7810a39633ba683545 /lib | |
parent | 39114d259c6e4bd5bb60b18f561d06cc24e8c852 (diff) | |
parent | 9c2a6e201388e7e30987a8679ddfa65b9422a38c (diff) | |
download | gitlab-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')
-rw-r--r-- | lib/api.rb | 1 | ||||
-rw-r--r-- | lib/api/groups.rb | 18 | ||||
-rw-r--r-- | lib/api/merge_requests.rb | 2 | ||||
-rw-r--r-- | lib/api/projects.rb | 75 | ||||
-rw-r--r-- | lib/api/system_hooks.rb | 60 | ||||
-rw-r--r-- | lib/api/users.rb | 20 | ||||
-rw-r--r-- | lib/extracts_path.rb | 6 | ||||
-rw-r--r-- | lib/tasks/gitlab/setup.rake | 10 |
8 files changed, 182 insertions, 10 deletions
diff --git a/lib/api.rb b/lib/api.rb index 3264f6a8fa6..d241f9b7479 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -33,5 +33,6 @@ module Gitlab mount MergeRequests mount Notes mount Internal + mount SystemHooks end end 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: diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index fd0050cfd5f..66b2f450545 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -105,12 +105,6 @@ module ExtractsPath # Automatically renders `not_found!` if a valid tree path could not be # resolved (e.g., when a user inserts an invalid path or ref). def assign_ref_vars - # Handle formats embedded in the id - if params[:id].ends_with?('.atom') - params[:id].gsub!(/\.atom$/, '') - request.format = :atom - end - path = CGI::unescape(request.fullpath.dup) @ref, @path = extract_ref(path) diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake index 8d4950cf396..5b74daf956e 100644 --- a/lib/tasks/gitlab/setup.rake +++ b/lib/tasks/gitlab/setup.rake @@ -7,10 +7,12 @@ namespace :gitlab do def setup_db warn_user_is_not_gitlab - puts "This will create the necessary database tables and seed the database." - puts "You will lose any previous data stored in the database." - ask_to_continue - puts "" + unless ENV['force'] == 'yes' + puts "This will create the necessary database tables and seed the database." + puts "You will lose any previous data stored in the database." + ask_to_continue + puts "" + end Rake::Task["db:setup"].invoke Rake::Task["db:seed_fu"].invoke |