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

#commit(project, sha) ⇒ Gitlab::ObjectifiedHash Also known as: repo_commit

Gets a specific commit identified by the commit hash or name of a branch or tag.

Examples:

Gitlab.commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
Gitlab.repo_commit(3, 'ed899a2f4b50b4370feeea94676502b42383c746')

Parameters:

  • project (Integer)

    The ID of a project.

  • sha (String)

    The commit hash or name of a repository branch or tag

Returns:



62
63
64
# File 'lib/gitlab/client/repositories.rb', line 62

def commit(project, sha)
  get("/projects/#{project}/repository/commits/#{sha}")
end

#commit_comments(project, commit, options = {}) ⇒ Array<Gitlab::ObjectifiedHash> Also known as: repo_commit_comments

Gets a list of comments for a commit.

Examples:

Gitlab.commit_comments(5, c9f9662a9b1116c838b523ed64c6abdb4aae4b8b)

Parameters:

  • project (Integer)

    The ID of a project.

  • sha (String)

    The commit hash or name of a repository branch or tag.

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



110
111
112
# File 'lib/gitlab/client/repositories.rb', line 110

def commit_comments(project, commit, options={})
  get("/projects/#{project}/repository/commits/#{commit}/comments", :query => options)
end

#commit_diff(project, sha) ⇒ Gitlab::ObjectifiedHash Also known as: repo_commit_diff

Get the diff of a commit in a project.

Examples:

Gitlab.commit_diff(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
Gitlab.repo_commit_diff(3, 'ed899a2f4b50b4370feeea94676502b42383c746')

Parameters:

  • project (Integer)

    The ID of a project.

  • sha (String)

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

Returns:



76
77
78
# File 'lib/gitlab/client/repositories.rb', line 76

def commit_diff(project, sha)
  get("/projects/#{project}/repository/commits/#{sha}/diff")
end

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

Gets a list of project commits.

Examples:

Gitlab.commits('viking')
Gitlab.repo_commits('gitlab', :ref_name => 'api')

Parameters:

  • project (Integer)

    The ID of a project.

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

    A customizable set of options.

Options Hash (options):

  • :ref_name (String)

    The branch or tag name of a project repository.

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



48
49
50
# File 'lib/gitlab/client/repositories.rb', line 48

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

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



156
157
158
# File 'lib/gitlab/client/repositories.rb', line 156

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

#create_commit_comment(project, commit, note, options = {}) ⇒ Gitlab::ObjectifiedHash Also known as: repo_create_commit_comment

Creates a new comment for a commit.

Parameters:

  • project (Integer)

    The ID of a project.

  • sha (String)

    The commit hash or name of a repository branch or tag.

  • note (String)

    The text of a comment.

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

    A customizable set of options.

Options Hash (options):

  • :path (String)

    The file path.

  • :line (Integer)

    The line number.

  • :line_type (String)

    The line type (new or old).

Returns:



125
126
127
# File 'lib/gitlab/client/repositories.rb', line 125

def create_commit_comment(project, commit, note, options={})
  post("/projects/#{project}/repository/commits/#{commit}/comments", :body => options.merge(:note => note))
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:

  • project (Integer)

    The ID of a project.

  • tag_name (String)

    The name of the new tag.

  • ref (String)

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

  • message (String) (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:

  • 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)


91
92
93
94
95
96
97
# File 'lib/gitlab/client/repositories.rb', line 91

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:

  • project (Integer)

    The ID 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/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:

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



141
142
143
# File 'lib/gitlab/client/repositories.rb', line 141

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