diff options
author | Marin Jankovski <maxlazio@gmail.com> | 2014-11-03 14:48:57 +0100 |
---|---|---|
committer | Marin Jankovski <maxlazio@gmail.com> | 2014-11-03 14:48:57 +0100 |
commit | b85b1f2690970aa9ed38d49166dcec90b26a1b17 (patch) | |
tree | 785a723760947aef2a3da5b0de55c564918654cf /lib/api/project_git_hook.rb | |
parent | 2ff68bfc2379bfbdc5a4f7cc9d9c10cae3c0cd79 (diff) | |
download | gitlab-ce-b85b1f2690970aa9ed38d49166dcec90b26a1b17.tar.gz |
Name the class singular, fix the failing spec.
Diffstat (limited to 'lib/api/project_git_hook.rb')
-rw-r--r-- | lib/api/project_git_hook.rb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/api/project_git_hook.rb b/lib/api/project_git_hook.rb new file mode 100644 index 00000000000..5a1523ab9c5 --- /dev/null +++ b/lib/api/project_git_hook.rb @@ -0,0 +1,76 @@ +module API + # Projects git hook API + class ProjectGitHook < Grape::API + before { authenticate! } + before { authorize_admin_project } + + resource :projects do + # Get project git hook + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # GET /projects/:id/git_hook + get ":id/git_hook" do + @git_hooks = user_project.git_hook + present @git_hooks, with: Entities::ProjectGitHook + end + + # Add git hook to project + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # POST /projects/:id/git_hook + post ":id/git_hook" do + attrs = attributes_for_keys [ + :commit_message_regex, + :deny_delete_tag + ] + + if user_project.git_hook + error!("Project git hook exists", 422) + else + @git_hook = user_project.create_git_hook(attrs) + present @git_hook, with: Entities::ProjectGitHook + end + end + + # Update an existing project git hook + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # PUT /projects/:id/git_hook + put ":id/git_hook" do + @git_hook = user_project.git_hook + + attrs = attributes_for_keys [ + :commit_message_regex, + :deny_delete_tag + ] + + if @git_hook && @git_hook.update_attributes(attrs) + present @git_hook, with: Entities::ProjectGitHook + else + not_found! + end + end + + # Deletes project git hook. This is an idempotent function. + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # DELETE /projects/:id/git_hook + delete ":id/git_hook" do + @git_hook = user_project.git_hook + if @git_hook + @git_hook.destroy + else + not_found! + end + end + end + end +end |