mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-18 00:56:41 +10:00
Add project git hooks api.
This commit is contained in:
@@ -41,6 +41,7 @@ module API
|
||||
mount ProjectMembers
|
||||
mount DeployKeys
|
||||
mount ProjectHooks
|
||||
mount ProjectGitHooks
|
||||
mount Ldap
|
||||
mount Services
|
||||
mount Files
|
||||
|
||||
@@ -34,6 +34,11 @@ module API
|
||||
expose :issues_events, :merge_requests_events, :tag_push_events
|
||||
end
|
||||
|
||||
class ProjectGitHook < Grape::Entity
|
||||
expose :id, :project_id, :created_at
|
||||
expose :commit_message_regex, :deny_delete_tag
|
||||
end
|
||||
|
||||
class ForkedFromProject < Grape::Entity
|
||||
expose :id
|
||||
expose :name, :name_with_namespace
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
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
|
||||
Reference in New Issue
Block a user