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:



29
30
31
# File 'lib/gitlab/client/branches.rb', line 29

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:



15
16
17
# File 'lib/gitlab/client/branches.rb', line 15

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:



78
79
80
# File 'lib/gitlab/client/branches.rb', line 78

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



91
92
93
# File 'lib/gitlab/client/branches.rb', line 91

def delete_branch(project, branch)
  delete("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
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:



49
50
51
# File 'lib/gitlab/client/branches.rb', line 49

def protect_branch(project, branch, options = {})
  post("/projects/#{url_encode project}/protected_branches", body: {name: branch}.merge(options))
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:



63
64
65
# File 'lib/gitlab/client/branches.rb', line 63

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