Method: Gitlab::Client::Branches#protect_branch

Defined in:
lib/gitlab/client/branches.rb

#protect_branch(project, branch, options = {}) ⇒ Gitlab::ObjectifiedHash Also known as: repo_protect_branch

Protects a repository branch.

To update options, call ‘protect_branch` again with new options (i.e. `developers_can_push: false`)

Examples:

Gitlab.protect_branch(3, 'api')
Gitlab.repo_protect_branch(5, 'master')
Gitlab.protect_branch(5, 'api', developers_can_push: true)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • branch (String)

    The name of the branch.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :developers_can_push (Boolean)

    True to allow developers to push to the branch (default = false)

  • :developers_can_merge (Boolean)

    True to allow developers to merge into the branch (default = false)

Returns:

[View source]

51
52
53
# File 'lib/gitlab/client/branches.rb', line 51

def protect_branch(project, branch, options = {})
  post("/projects/#{url_encode project}/protected_branches", body: { name: branch }.merge(options))
end