summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-04-06 16:48:47 +0300
committerValery Sizov <vsv2711@gmail.com>2015-04-06 16:48:47 +0300
commitdcfb69aabb93fe945d5b7ac9497eafec2c1f7df5 (patch)
treec204d6794e1fcae76d4dc3b1585d88ba5b7401a5 /lib/api
parent1bb72f838cde2d7f3cfd3e55c2e189499ff0f1cb (diff)
downloadgitlab-ci-dcfb69aabb93fe945d5b7ac9497eafec2c1f7df5.tar.gz
support for forks
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/forks.rb38
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index a969e4b..d1127ed 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -29,5 +29,6 @@ module API
mount Commits
mount Runners
mount Projects
+ mount Forks
end
end
diff --git a/lib/api/forks.rb b/lib/api/forks.rb
new file mode 100644
index 0000000..248eb3b
--- /dev/null
+++ b/lib/api/forks.rb
@@ -0,0 +1,38 @@
+module API
+ class Forks < Grape::API
+ resource :forks do
+ # Create a fork
+ #
+ # Parameters:
+ # project_id (required) - The ID of a project
+ # project_token (requires) - Project token
+ # user_token(required) - User private token
+ # data (required) - GitLab push data
+ #
+ #
+ # Example Request:
+ # POST /forks
+ post do
+ required_attributes! [:project_id, :data, :project_token, :user_token]
+ project = Project.find_by!(gitlab_id: params[:project_id])
+ authenticate_project_token!(project)
+
+ user_session = UserSession.new
+ user = user_session.authenticate_by_token(private_token: params[:user_token], url: GitlabCi.config.gitlab_server.url)
+
+ fork = CreateProjectService.new.execute(
+ user,
+ params[:data],
+ RoutesHelper.project_url(":project_id"),
+ project
+ )
+
+ if fork
+ present fork, with: Entities::Project
+ else
+ not_found!
+ end
+ end
+ end
+ end
+end