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:

  • project (Integer)

    The ID of a project.

  • from (String)

    The commit SHA or branch name of from branch.

  • to (String)

    The commit SHA or branch name of to branch.

Returns:



73
74
75
# File 'lib/gitlab/client/repositories.rb', line 73

def compare(project, from, to)
  get("/projects/#{project}/repository/compare", query: { from: from, to: to })
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:

  • project (Integer)

    The ID of a project.

  • filepath (String)

    The relative path of the file in the repository

  • ref (String) (defaults to: 'master')

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

Returns:

  • (String)


15
16
17
18
19
20
21
# File 'lib/gitlab/client/repositories.rb', line 15

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

#repo_archive(project, ref = 'master') ⇒ Gitlab::FileResponse

Get project repository archive

Examples:

Gitlab.repo_archive(42)
Gitlab.repo_archive(42, 'deadbeef')

Parameters:

  • project (Integer)

    The ID of a project.

  • ref (String) (defaults to: 'master')

    The commit sha, branch, or tag to download.

Returns:



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gitlab/client/repositories.rb', line 49

def repo_archive(project, ref = 'master')
  get("/projects/#{project}/repository/archive",
      format: nil,
      headers: { Accept: 'application/octet-stream' },
      query: { sha: ref },
      parser: proc { |body, _|
        if body.encoding == Encoding::ASCII_8BIT # binary response
          ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
        else # error with json response
          ::Gitlab::Request.parse(body)
        end
      })
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:

  • project (Integer)

    The ID of a project.

  • options (Hash) (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:



35
36
37
# File 'lib/gitlab/client/repositories.rb', line 35

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