Commit 6c0ae72c authored by Marin Jankovski's avatar Marin Jankovski

Add project git hooks api.

parent e180e6d5
...@@ -41,6 +41,7 @@ module API ...@@ -41,6 +41,7 @@ module API
mount ProjectMembers mount ProjectMembers
mount DeployKeys mount DeployKeys
mount ProjectHooks mount ProjectHooks
mount ProjectGitHooks
mount Ldap mount Ldap
mount Services mount Services
mount Files mount Files
......
...@@ -34,6 +34,11 @@ module API ...@@ -34,6 +34,11 @@ module API
expose :issues_events, :merge_requests_events, :tag_push_events expose :issues_events, :merge_requests_events, :tag_push_events
end end
class ProjectGitHook < Grape::Entity
expose :id, :project_id, :created_at
expose :commit_message_regex, :deny_delete_tag
end
class ForkedFromProject < Grape::Entity class ForkedFromProject < Grape::Entity
expose :id expose :id
expose :name, :name_with_namespace expose :name, :name_with_namespace
......
module API
# Projects git hook API
class ProjectGitHooks < 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.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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment