Commit 65e1a06e authored by Robert Schilling's avatar Robert Schilling

Grapify the project git hooks API

parent cf046802
...@@ -7,72 +7,71 @@ module API ...@@ -7,72 +7,71 @@ module API
before { authenticate! } before { authenticate! }
before { authorize_admin_project } before { authorize_admin_project }
DEPRECATION_MESSAGE = 'This endpoint is deprecated, replaced with push_rules, and will be removed in GitLab 9.0.'.freeze
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do resource :projects do
# Get project push rule helpers do
# params :push_rule_params do
# Parameters: optional :commit_message_regex, type: String, desc: 'The commit message regex'
# id (required) - The ID of a project optional :deny_delete_tag, type: Boolean, desc: 'Deny deleting a tag'
# Example Request: at_least_one_of :commit_message_regex, :deny_delete_tag
# GET /projects/:id/push_rule end
end
desc 'Get project push rule' do
success Entities::ProjectPushRule
detail DEPRECATION_MESSAGE
end
get ":id/git_hook" do get ":id/git_hook" do
@push_rule = user_project.push_rule push_rule = user_project.push_rule
present @push_rule, with: Entities::ProjectPushRule present push_rule, with: Entities::ProjectPushRule
end end
# Add push rule to project desc 'Add a push rule to a project' do
# success Entities::ProjectPushRule
# Parameters: detail DEPRECATION_MESSAGE
# id (required) - The ID of a project end
# Example Request: params do
# POST /projects/:id/push_rule use :push_rule_params
end
post ":id/git_hook" do post ":id/git_hook" do
attrs = attributes_for_keys [
:commit_message_regex,
:deny_delete_tag
]
if user_project.push_rule if user_project.push_rule
error!("Project push rule exists", 422) error!("Project push rule exists", 422)
else else
@push_rule = user_project.create_push_rule(attrs) push_rule = user_project.create_push_rule(declared_params)
present @push_rule, with: Entities::ProjectPushRule present push_rule, with: Entities::ProjectPushRule
end end
end end
# Update an existing project push rule desc 'Update an existing project push rule' do
# success Entities::ProjectPushRule
# Parameters: detail DEPRECATION_MESSAGE
# id (required) - The ID of a project end
# Example Request: params do
# PUT /projects/:id/push_rule use :push_rule_params
end
put ":id/git_hook" do put ":id/git_hook" do
@push_rule = user_project.push_rule push_rule = user_project.push_rule
not_found!('Push Rule') unless push_rule
attrs = attributes_for_keys [
:commit_message_regex,
:deny_delete_tag
]
if @push_rule && @push_rule.update_attributes(attrs) if push_rule.update_attributes(declared_params(include_missing: false))
present @push_rule, with: Entities::ProjectPushRule present push_rule, with: Entities::ProjectPushRule
else else
not_found! render_validation_error!(push_rule)
end end
end end
# Deletes project push rule. This is an idempotent function. desc 'Deletes project push rule' do
# detail DEPRECATION_MESSAGE
# Parameters: end
# id (required) - The ID of a project
# Example Request:
# DELETE /projects/:id/push_rule
delete ":id/git_hook" do delete ":id/git_hook" do
@push_rule = user_project.push_rule push_rule = user_project.push_rule
if @push_rule not_found!('Push Rule') unless push_rule
@push_rule.destroy
else push_rule.destroy
not_found!
end
end 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