Module: Gitlab::Client::Branches

Included in:
Gitlab::Client
Defined in:
lib/gitlab/client/branches.rb

Overview

Defines methods related to repositories.

Instance Method Summary collapse

Instance Method Details

#branch(project, branch) ⇒ Gitlab::ObjectifiedHash Also known as: repo_branch

Gets information about a repository branch.

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • branch (String)

    The name of the branch.

Returns:



31
32
33
# File 'lib/gitlab/client/branches.rb', line 31

def branch(project, branch)
  get("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
end

#branches(project, options = {}) ⇒ Array<Gitlab::ObjectifiedHash> Also known as: repo_branches

Gets a list of project repositiory branches.

Examples:

Gitlab.branches(42)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

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

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



17
18
19
# File 'lib/gitlab/client/branches.rb', line 17

def branches(project, options = {})
  get("/projects/#{url_encode project}/repository/branches", query: options)
end

#create_branch(project, branch, ref) ⇒ Gitlab::ObjectifiedHash Also known as: repo_create_branch

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

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • branch (String)

    The name of the new branch.

  • ref (String)

    Create branch from commit sha or existing branch

Returns:



80
81
82
# 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

#delete_branch(project, branch) ⇒ Object Also known as: repo_delete_branch

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

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • branch (String)

    The name of the branch to delete



93
94
95
# File 'lib/gitlab/client/branches.rb', line 93

def delete_branch(project, branch)
  delete("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
end

#delete_merged_branches(project) ⇒ nil Also known as: repo_delete_merged_branches

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

Examples:

Gitlab.delete_merged_branches(3)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

Returns:

  • (nil)

    This API call returns an empty response body.



105
106
107
# File 'lib/gitlab/client/branches.rb', line 105

def delete_merged_branches(project)
  delete("/projects/#{url_encode project}/repository/merged_branches")
end

#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:



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

#protected_branch(project, branch) ⇒ Gitlab::ObjectifiedHash Also known as: repo_protected_branch

Gets a single protected branch or wildcard protected branch

Examples:

Gitlab.protected_branch(3, 'api')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • name (String)

    The name of the branch or wildcard

Returns:



130
131
132
# File 'lib/gitlab/client/branches.rb', line 130

def protected_branch(project, branch)
  get("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
end

#protected_branches(project) ⇒ Array<Gitlab::ObjectifiedHash> Also known as: repo_protected_branches

Gets a list of protected branches from a project.

Examples:

Gitlab.protected_branches(42)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

Returns:



117
118
119
# File 'lib/gitlab/client/branches.rb', line 117

def protected_branches(project)
  get("/projects/#{url_encode project}/protected_branches")
end

#unprotect_branch(project, branch) ⇒ Gitlab::ObjectifiedHash Also known as: repo_unprotect_branch

Unprotects a repository branch.

Examples:

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

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • branch (String)

    The name of the branch.

Returns:



65
66
67
# File 'lib/gitlab/client/branches.rb', line 65

def unprotect_branch(project, branch)
  delete("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
end