module Gitlab::Client::Branches

Defines methods related to repositories. @see docs.gitlab.com/ce/api/branches.html

Public Instance Methods

branch(project, branch) click to toggle source

Gets information about a repository branch.

@example

Gitlab.branch(3, 'api')
Gitlab.repo_branch(5, 'master')

@param [Integer, String] project The ID or name of a project. @param [String] branch The name of the branch. @return [Gitlab::ObjectifiedHash]

# File lib/gitlab/client/branches.rb, line 31
def branch(project, branch)
  get("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
end
Also aliased as: repo_branch
branches(project, options = {}) click to toggle source

Gets a list of project repositiory branches.

@example

Gitlab.branches(42)

@param [Integer, String] project The ID or name of a project. @param [Hash] options A customizable set of options. @option options [Integer] :page The page number. @option options [Integer] :per_page The number of results per page. @return [Array<Gitlab::ObjectifiedHash>]

# File lib/gitlab/client/branches.rb, line 17
def branches(project, options = {})
  get("/projects/#{url_encode project}/repository/branches", query: options)
end
Also aliased as: repo_branches
create_branch(project, branch, ref) click to toggle source

Creates a repository branch. Requires Gitlab >= 6.8.x

@example

Gitlab.create_branch(3, 'api', 'feat/new-api')
Gitlab.repo_create_branch(5, 'master', 'develop')

@param [Integer, String] project The ID or name of a project. @param [String] branch The name of the new branch. @param [String] ref Create branch from commit sha or existing branch @return [Gitlab::ObjectifiedHash] Details about the branch

# File lib/gitlab/client/branches.rb, line 80
def create_branch(project, branch, ref)
  post("/projects/#{url_encode project}/repository/branches", query: { branch: branch, ref: ref })
end
Also aliased as: repo_create_branch
delete_branch(project, branch) click to toggle source

Deletes a repository branch. Requires Gitlab >= 6.8.x

@example

Gitlab.delete_branch(3, 'api')
Gitlab.repo_delete_branch(5, 'master')

@param [Integer, String] project The ID or name of a project. @param [String] branch The name of the branch to delete

# File lib/gitlab/client/branches.rb, line 93
def delete_branch(project, branch)
  delete("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
end
Also aliased as: repo_delete_branch
delete_merged_branches(project) click to toggle source

Delete all branches that are merged into the project default branch. Protected branches will not be deleted as part of this operation.

@example

Gitlab.delete_merged_branches(3)

@param [Integer, String] project The ID or name of a project. @return [nil] This API call returns an empty response body.

# File lib/gitlab/client/branches.rb, line 105
def delete_merged_branches(project)
  delete("/projects/#{url_encode project}/repository/merged_branches")
end
Also aliased as: repo_delete_merged_branches
protect_branch(project, branch, options = {}) click to toggle source

Protects a repository branch.

@example

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

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

@param [Integer, String] project The ID or name of a project. @param [String] branch The name of the branch. @param [Hash] options A customizable set of options. @option options [Boolean] :developers_can_push True to allow developers to push to the branch (default = false) @option options [Boolean] :developers_can_merge True to allow developers to merge into the branch (default = false) @return [Gitlab::ObjectifiedHash] Details about the branch

# 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
Also aliased as: repo_protect_branch
protected_branch(project, branch) click to toggle source

Gets a single protected branch or wildcard protected branch

@example

Gitlab.protected_branch(3, 'api')

@param [Integer, String] project The ID or name of a project. @param [String] name The name of the branch or wildcard @return [Gitlab::ObjectifiedHash]

# File lib/gitlab/client/branches.rb, line 130
def protected_branch(project, branch)
  get("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
end
Also aliased as: repo_protected_branch
protected_branches(project) click to toggle source

Gets a list of protected branches from a project.

@example

Gitlab.protected_branches(42)

@param [Integer, String] project The ID or name of a project. @return [Array<Gitlab::ObjectifiedHash>]

# File lib/gitlab/client/branches.rb, line 117
def protected_branches(project)
  get("/projects/#{url_encode project}/protected_branches")
end
Also aliased as: repo_protected_branches
repo_branch(project, branch)
Alias for: branch
repo_branches(project, options = {})
Alias for: branches
repo_create_branch(project, branch, ref)
Alias for: create_branch
repo_delete_branch(project, branch)
Alias for: delete_branch
repo_delete_merged_branches(project)
repo_protect_branch(project, branch, options = {})
Alias for: protect_branch
repo_protected_branch(project, branch)
Alias for: protected_branch
repo_protected_branches(project)
Alias for: protected_branches
repo_unprotect_branch(project, branch)
Alias for: unprotect_branch
unprotect_branch(project, branch) click to toggle source

Unprotects a repository branch.

@example

Gitlab.unprotect_branch(3, 'api')
Gitlab.repo_unprotect_branch(5, 'master')

@param [Integer, String] project The ID or name of a project. @param [String] branch The name of the branch. @return [Gitlab::ObjectifiedHash] Details about the branch

# File lib/gitlab/client/branches.rb, line 65
def unprotect_branch(project, branch)
  delete("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
end
Also aliased as: repo_unprotect_branch