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:



56
57
58
# File 'lib/gitlab/client/repositories.rb', line 56

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

#merge_base(project, refs) ⇒ Gitlab::ObjectifiedHash

Get the common ancestor for 2 refs (commit SHAs, branch names or tags).

Examples:

Gitlab.merge_base(42, ['master', 'feature/branch'])
Gitlab.merge_base(42, ['master', 'feature/branch'])

Parameters:

  • project (Integer, String)

    The ID or URL-encoded path of the project.

  • refs (Array)

    Array containing 2 commit SHAs, branch names, or tags.

Returns:



70
71
72
# File 'lib/gitlab/client/repositories.rb', line 70

def merge_base(project, refs)
  get("/projects/#{url_encode project}/repository/merge_base", query: { refs: refs })
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, String)

    The ID or name of a project.

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

    The commit sha, branch, or tag to download.

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/client/repositories.rb', line 32

def repo_archive(project, ref = 'master')
  get("/projects/#{url_encode 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, String)

    The ID or name 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:



18
19
20
# File 'lib/gitlab/client/repositories.rb', line 18

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