BigW Consortium Gitlab

Commit a56e35e9 by Dmitriy Zaporozhets

Merge branch 'api-branch-deletion' into 'master'

Api branch deletion Fixes #1127
parents 68942dbb d575ee3e
......@@ -199,3 +199,17 @@ Parameters:
"protected": false
}
```
## Delete repository branch
```
DELETE /projects/:id/repository/branches/:branch
```
Parameters:
+ `id` (required) - The ID of a project
+ `branch` (required) - The name of the branch
It return 200 if succeed or 405 if failed with error message explaining reason.
......@@ -94,7 +94,13 @@ module API
# DELETE /projects/:id/repository/branches/:branch
delete ":id/repository/branches/:branch" do
authorize_push_project
DeleteBranchService.new.execute(user_project, params[:branch], current_user)
result = DeleteBranchService.new.execute(user_project, params[:branch], current_user)
if result[:state] == :success
true
else
render_api_error!(result[:message], 405)
end
end
end
end
......
......@@ -91,7 +91,6 @@ describe API::API, api: true do
end
end
describe "POST /projects/:id/repository/branches" do
it "should create a new branch" do
post api("/projects/#{project.id}/repository/branches", user),
......@@ -112,4 +111,26 @@ describe API::API, api: true do
response.status.should == 403
end
end
describe "DELETE /projects/:id/repository/branches/:branch" do
before { Repository.any_instance.stub(rm_branch: true) }
it "should remove branch" do
delete api("/projects/#{project.id}/repository/branches/new_design", user)
response.status.should == 200
end
it "should remove protected branch" do
project.protected_branches.create(name: 'new_design')
delete api("/projects/#{project.id}/repository/branches/new_design", user)
response.status.should == 405
json_response['message'].should == 'Protected branch cant be removed'
end
it "should not remove HEAD branch" do
delete api("/projects/#{project.id}/repository/branches/master", user)
response.status.should == 405
json_response['message'].should == 'Cannot remove HEAD branch'
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