Module: Gitlab::Client::Repositories

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

Overview

Defines methods related to repositories.

Instance Method Summary collapse

Instance Method Details

#compare(project, from, to) ⇒ Gitlab::ObjectifiedHash Also known as: repo_compare

Compares branches, tags or commits.

Examples:

Gitlab.compare(42, 'master', 'feature/branch')
Gitlab.repo_compare(42, 'master', 'feature/branch')

Parameters:

  • The ID of a project.

  • The commit SHA or branch name of from branch.

  • The commit SHA or branch name of to branch.

Returns:



81
82
83
# File 'lib/gitlab/client/repositories.rb', line 81

def compare(project, from, to)
  get("/projects/#{project}/repository/compare", query: { from: from, to: to })
end

#create_tag(project, tag_name, ref, message = '') ⇒ Gitlab::ObjectifiedHash Also known as: repo_create_tag

Creates a new project repository tag.

Examples:

Gitlab.create_tag(42, 'new_tag', 'master')
Gitlab.create_tag(42, 'v1.0', 'master', 'Release 1.0')

Parameters:

  • The ID of a project.

  • The name of the new tag.

  • The ref (commit sha, branch name, or another tag) the tag will point to.

  • (defaults to: '')

    Optional message for tag, creates annotated tag if specified.

Returns:



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

def create_tag(project, tag_name, ref, message='')
  post("/projects/#{project}/repository/tags", body: { tag_name: tag_name, ref: ref, message: message })
end

#file_contents(project, filepath, ref = 'master') ⇒ String Also known as: repo_file_contents

Get the contents of a file

Examples:

Gitlab.file_contents(42, 'Gemfile')
Gitlab.repo_file_contents(3, 'Gemfile', 'ed899a2f4b50b4370feeea94676502b42383c746')

Parameters:

  • The ID of a project.

  • The relative path of the file in the repository

  • (defaults to: 'master')

    The name of a repository branch or tag or if not given the default branch.

Returns:



46
47
48
49
50
51
52
# File 'lib/gitlab/client/repositories.rb', line 46

def file_contents(project, filepath, ref='master')
  ref = URI.encode(ref, /\W/)
  get "/projects/#{project}/repository/blobs/#{ref}?filepath=#{filepath}",
      format: nil,
      headers: { Accept: 'text/plain' },
      parser: ::Gitlab::Request::Parser
end

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

Gets a list of project repository tags.

Examples:

Gitlab.tags(42)

Parameters:

  • The ID of a project.

  • (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/repositories.rb', line 15

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

#tree(project, options = {}) ⇒ Gitlab::ObjectifiedHash Also known as: repo_tree

Get file tree project (root level).

Examples:

Gitlab.tree(42)
Gitlab.tree(42, path: "Gemfile")

Parameters:

  • The ID of a project.

  • (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :path (String)

    The path inside repository.

  • :ref_name (String)

    The name of a repository branch or tag.

Returns:



66
67
68
# File 'lib/gitlab/client/repositories.rb', line 66

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