Added methods to protect and unprotect branches in from the API
Created by: m4tthumphrey
Provides methods in the API to manage protected branches. See documentation for usage.
Merge request reports
Activity
Created by: m4tthumphrey
Fixes #1947 (closed)
By Administrator on 2013-01-29T21:13:01 (imported from GitLab project)
By Administrator on 2013-01-29T21:13:01 (imported from GitLab)
218 218 # Example Request: 219 219 # GET /projects/:id/repository/branches 220 220 get ":id/repository/branches" do 221 present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject 221 present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project 230 230 # GET /projects/:id/repository/branches/:branch 231 231 get ":id/repository/branches/:branch" do 232 232 @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } 233 present @branch, with: Entities::RepoObject 233 present @branch, with: Entities::RepoObject, project: user_project 236 # Protect a single branch 237 # 238 # Parameters: 239 # id (required) - The ID of a project 240 # branch (required) - The name of the branch 241 # Example Request: 242 # PUT /projects/:id/repository/branches/:branch/protect 243 put ":id/repository/branches/:branch/protect" do 244 @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } 245 protected = user_project.protected_branches.find_by_name(@branch.name) 246 247 unless protected 248 user_project.protected_branches.create(:name => @branch.name) 249 end 250 251 present @branch, with: Entities::RepoObject, project: user_project 254 # Unprotect a single branch 255 # 256 # Parameters: 257 # id (required) - The ID of a project 258 # branch (required) - The name of the branch 259 # Example Request: 260 # PUT /projects/:id/repository/branches/:branch/unprotect 261 put ":id/repository/branches/:branch/unprotect" do 262 @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } 263 protected = user_project.protected_branches.find_by_name(@branch.name) 264 265 if protected 266 protected.destroy 267 end 268 269 present @branch, with: Entities::RepoObject, project: user_project 73 74 }, 74 75 "authored_date": "2012-06-27T05:51:39-07:00", 75 76 "committed_date": "2012-06-28T03:44:20-07:00" 76 } 77 }, 78 "protected": true 79 } 80 ``` 81 82 ## Protect a project repository branch 83 84 Protect a single project repository branch. 85 86 ``` 87 PUT /projects/:id/repository/branches/:branch/protect 112 "name": "John Smith", 113 "email": "john@example.com" 114 }, 115 "authored_date": "2012-06-27T05:51:39-07:00", 116 "committed_date": "2012-06-28T03:44:20-07:00" 117 }, 118 "protected": true 119 } 120 ``` 121 122 ## Unprotect a project repository branch 123 124 Unprotect a single project repository branch. 125 126 ``` 127 PUT /projects/:id/repository/branches/:branch/unprotect 218 218 # Example Request: 219 219 # GET /projects/:id/repository/branches 220 220 get ":id/repository/branches" do 221 present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject 221 present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project Created by: vsizov
nice one. But there is one issue. I think that update single branch must be implemented through put request according to rest. Don't you think so?
By Administrator on 2013-01-30T09:09:36 (imported from GitLab project)
By Administrator on 2013-01-30T09:09:36 (imported from GitLab)
Created by: AlexDenisov
@vsizov, according to rest there should be something like that
GET /projects/:id/repository/protected_branches POST /projects/:id/repository/protected_branches DELETE /projects/:id/repository/protected_branches
imho.
By Administrator on 2013-01-30T09:15:53 (imported from GitLab project)
By Administrator on 2013-01-30T09:15:53 (imported from GitLab)
Created by: vsizov
@AlexDenisov I agree with you
By Administrator on 2013-01-30T09:19:55 (imported from GitLab project)
By Administrator on 2013-01-30T09:19:55 (imported from GitLab)
218 218 # Example Request: 219 219 # GET /projects/:id/repository/branches 220 220 get ":id/repository/branches" do 221 present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject 221 present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project Created by: m4tthumphrey
Would you accept both methods? Ie keeping the /protect /unprotect as well as adding the proper REST style:
GET /projects/:id/repository/protected_branches POST /projects/:id/repository/protected_branches DELETE /projects/:id/repository/protected_branches
By Administrator on 2013-01-30T09:36:33 (imported from GitLab project)
By Administrator on 2013-01-30T09:36:33 (imported from GitLab)
73 74 }, 74 75 "authored_date": "2012-06-27T05:51:39-07:00", 75 76 "committed_date": "2012-06-28T03:44:20-07:00" 76 } 77 }, 78 "protected": true 79 } 80 ``` 81 82 ## Protect a project repository branch 83 84 Protect a single project repository branch. 85 86 ``` 87 PUT /projects/:id/repository/branches/:branch/protect