Skip to content
Snippets Groups Projects

Added methods to protect and unprotect branches in from the API

Merged gitlab-qa-bot requested to merge github/fork/screenpages/protected-branches-api into master

Created by: m4tthumphrey

Provides methods in the API to manage protected branches. See documentation for usage.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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: AlexDenisov

    project: user_project

    By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

    By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • gitlab-qa-bot
  • 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
    • Created by: AlexDenisov

      project: user_project

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • gitlab-qa-bot
  • 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
    • Created by: AlexDenisov

      project: user_project

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • gitlab-qa-bot
  • 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
    • Created by: AlexDenisov

      project: user_project

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • gitlab-qa-bot
  • 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
    • Created by: vsizov

      you've added post request as i understood.

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • gitlab-qa-bot
  • 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
    • Created by: vsizov

      the same

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • gitlab-qa-bot
  • 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

      why?

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • 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)

  • gitlab-qa-bot
  • 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

      So that the branches can contain the protected attribute.

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • Created by: vsizov

    The main idea: Every request that going to change single item must be PUT.

    By Administrator on 2013-01-30T09:22:26 (imported from GitLab project)

    By Administrator on 2013-01-30T09:22:26 (imported from GitLab)

  • 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)

  • gitlab-qa-bot
  • 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
    • Created by: m4tthumphrey

      Yes I did. Woops!

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab project)

      By Administrator on 2013-01-31T09:28:29 (imported from GitLab)

  • Created by: dzaporozhets

    Please squash the commits and we will accept this one

    By Administrator on 2013-01-31T06:27:26 (imported from GitLab project)

    By Administrator on 2013-01-31T06:27:26 (imported from GitLab)

  • Created by: m4tthumphrey

    @randx done!

    By Administrator on 2013-01-31T09:29:07 (imported from GitLab project)

    By Administrator on 2013-01-31T09:29:07 (imported from GitLab)

  • Created by: dzaporozhets

    Thank you

    By Administrator on 2013-01-31T18:44:14 (imported from GitLab project)

    By Administrator on 2013-01-31T18:44:14 (imported from GitLab)

  • Please register or sign in to reply
    Loading