Commit a56e35e9250b23c8949780fb2f5d8ed236c6d536
Exists in
spb-stable
and in
2 other branches
Merge branch 'api-branch-deletion' into 'master'
Api branch deletion Fixes #1127
Showing
3 changed files
with
43 additions
and
2 deletions
Show diff stats
doc/api/branches.md
@@ -199,3 +199,17 @@ Parameters: | @@ -199,3 +199,17 @@ Parameters: | ||
199 | "protected": false | 199 | "protected": false |
200 | } | 200 | } |
201 | ``` | 201 | ``` |
202 | + | ||
203 | +## Delete repository branch | ||
204 | + | ||
205 | + | ||
206 | +``` | ||
207 | +DELETE /projects/:id/repository/branches/:branch | ||
208 | +``` | ||
209 | + | ||
210 | +Parameters: | ||
211 | + | ||
212 | ++ `id` (required) - The ID of a project | ||
213 | ++ `branch` (required) - The name of the branch | ||
214 | + | ||
215 | +It return 200 if succeed or 405 if failed with error message explaining reason. |
lib/api/branches.rb
@@ -94,7 +94,13 @@ module API | @@ -94,7 +94,13 @@ module API | ||
94 | # DELETE /projects/:id/repository/branches/:branch | 94 | # DELETE /projects/:id/repository/branches/:branch |
95 | delete ":id/repository/branches/:branch" do | 95 | delete ":id/repository/branches/:branch" do |
96 | authorize_push_project | 96 | authorize_push_project |
97 | - DeleteBranchService.new.execute(user_project, params[:branch], current_user) | 97 | + result = DeleteBranchService.new.execute(user_project, params[:branch], current_user) |
98 | + | ||
99 | + if result[:state] == :success | ||
100 | + true | ||
101 | + else | ||
102 | + render_api_error!(result[:message], 405) | ||
103 | + end | ||
98 | end | 104 | end |
99 | end | 105 | end |
100 | end | 106 | end |
spec/requests/api/branches_spec.rb
@@ -91,7 +91,6 @@ describe API::API, api: true do | @@ -91,7 +91,6 @@ describe API::API, api: true do | ||
91 | end | 91 | end |
92 | end | 92 | end |
93 | 93 | ||
94 | - | ||
95 | describe "POST /projects/:id/repository/branches" do | 94 | describe "POST /projects/:id/repository/branches" do |
96 | it "should create a new branch" do | 95 | it "should create a new branch" do |
97 | post api("/projects/#{project.id}/repository/branches", user), | 96 | post api("/projects/#{project.id}/repository/branches", user), |
@@ -112,4 +111,26 @@ describe API::API, api: true do | @@ -112,4 +111,26 @@ describe API::API, api: true do | ||
112 | response.status.should == 403 | 111 | response.status.should == 403 |
113 | end | 112 | end |
114 | end | 113 | end |
114 | + | ||
115 | + describe "DELETE /projects/:id/repository/branches/:branch" do | ||
116 | + before { Repository.any_instance.stub(rm_branch: true) } | ||
117 | + | ||
118 | + it "should remove branch" do | ||
119 | + delete api("/projects/#{project.id}/repository/branches/new_design", user) | ||
120 | + response.status.should == 200 | ||
121 | + end | ||
122 | + | ||
123 | + it "should remove protected branch" do | ||
124 | + project.protected_branches.create(name: 'new_design') | ||
125 | + delete api("/projects/#{project.id}/repository/branches/new_design", user) | ||
126 | + response.status.should == 405 | ||
127 | + json_response['message'].should == 'Protected branch cant be removed' | ||
128 | + end | ||
129 | + | ||
130 | + it "should not remove HEAD branch" do | ||
131 | + delete api("/projects/#{project.id}/repository/branches/master", user) | ||
132 | + response.status.should == 405 | ||
133 | + json_response['message'].should == 'Cannot remove HEAD branch' | ||
134 | + end | ||
135 | + end | ||
115 | end | 136 | end |