From f030ee846ed39c5e0a326e8ba117ec79f40e230d Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Wed, 1 Oct 2014 10:20:40 +0200 Subject: API: Initial support for forking a project via the API This change adds POST /projects/fork/:id to the API for forking a project into the namespace of the authenticated user, like the "create fork" link in the GUI does. It also calls the same code. Failure and permission checks (except for conflict) are already implemented and handled in ForkService and the API, so the added code is simple and does not alter anything. --- lib/api/projects.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/api/projects.rb') diff --git a/lib/api/projects.rb b/lib/api/projects.rb index f555819df1b..7f7d2f8e9a8 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -153,6 +153,23 @@ module API end end + # Fork new project for the current user. + # + # Parameters: + # id (required) - The ID of a project + # Example Request + # POST /projects/fork/:id + post 'fork/:id' do + @forked_project = + ::Projects::ForkService.new(user_project, + current_user).execute + if @forked_project.errors.any? + conflict!(@forked_project.errors.messages) + else + present @forked_project, with: Entities::Project + end + end + # Remove project # # Parameters: -- cgit v1.2.1