Commit 7e115252 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'grapify-push-rules' into 'master'

Grapify the push rules API

See merge request !1005
parents daced567 497af21c
......@@ -4,72 +4,64 @@ module API
before { authenticate! }
before { authorize_admin_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects do
# Get project push rule
#
# Parameters:
# id (required) - The ID of a project
# Example Request:
# GET /projects/:id/push_rule
helpers do
params :push_rule_params do
optional :commit_message_regex, type: String, desc: 'The commit message regex'
optional :deny_delete_tag, type: Boolean, desc: 'Deny deleting a tag'
at_least_one_of :commit_message_regex, :deny_delete_tag
end
end
desc 'Get project push rule' do
success Entities::ProjectPushRule
end
get ":id/push_rule" do
@push_rule = user_project.push_rule
present @push_rule, with: Entities::ProjectPushRule
push_rule = user_project.push_rule
present push_rule, with: Entities::ProjectPushRule
end
# Add push rule to project
#
# Parameters:
# id (required) - The ID of a project
# Example Request:
# POST /projects/:id/push_rule
desc 'Add a push rule to a project' do
success Entities::ProjectPushRule
end
params do
use :push_rule_params
end
post ":id/push_rule" do
attrs = attributes_for_keys [
:commit_message_regex,
:deny_delete_tag
]
if user_project.push_rule
error!("Project push rule exists", 422)
else
@push_rule = user_project.create_push_rule(attrs)
present @push_rule, with: Entities::ProjectPushRule
push_rule = user_project.create_push_rule(declared_params)
present push_rule, with: Entities::ProjectPushRule
end
end
# Update an existing project push rule
#
# Parameters:
# id (required) - The ID of a project
# Example Request:
# PUT /projects/:id/push_rule
desc 'Update an existing project push rule' do
success Entities::ProjectPushRule
end
params do
use :push_rule_params
end
put ":id/push_rule" do
@push_rule = user_project.push_rule
attrs = attributes_for_keys [
:commit_message_regex,
:deny_delete_tag
]
push_rule = user_project.push_rule
not_found!('Push Rule') unless push_rule
if @push_rule && @push_rule.update_attributes(attrs)
present @push_rule, with: Entities::ProjectPushRule
if push_rule.update_attributes(declared_params(include_missing: false))
present push_rule, with: Entities::ProjectPushRule
else
not_found!
render_validation_error!(push_rule)
end
end
# Deletes project push rule. This is an idempotent function.
#
# Parameters:
# id (required) - The ID of a project
# Example Request:
# DELETE /projects/:id/push_rule
desc 'Deletes project push rule'
delete ":id/push_rule" do
@push_rule = user_project.push_rule
if @push_rule
@push_rule.destroy
else
not_found!
end
push_rule = user_project.push_rule
not_found!('Push Rule') unless push_rule
push_rule.destroy
end
end
end
......
......@@ -128,7 +128,7 @@ describe API::ProjectPushRule, 'ProjectPushRule', api: true do
expect(response.status).to eq(404)
expect(json_response).to be_an Hash
expect(json_response['message']).to eq("404 Not Found")
expect(json_response['message']).to eq('404 Push Rule Not Found')
end
it "returns a 403 error if not authorized" do
......
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