Module: Gitlab::Client::Commits

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

Overview

Defines methods related to repository commits.

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:



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

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:



60
61
62
# File 'lib/gitlab/client/commits.rb', line 60

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:



45
46
47
# File 'lib/gitlab/client/commits.rb', line 45

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

#commit_status(id, sha, options = {}) ⇒ Object Also known as: repo_commit_status

Get the status of a commit

Examples:

Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', name: 'jenkins')
Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', name: 'jenkins', all: true)

Parameters:

  • project (Integer)

    The ID of a project.

  • sha (String)

    The commit hash

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

    A customizable set of options.

Options Hash (options):

  • :ref (String)

    Filter by ref name, it can be branch or tag

  • :stage (String)

    Filter by stage

  • :name (String)

    Filer by status name, eg. jenkins

  • :all (Boolean)

    The flag to return all statuses, not only latest ones



97
98
99
# File 'lib/gitlab/client/commits.rb', line 97

def commit_status(id, sha, options={})
  get("/projects/#{id}/repository/commits/#{sha}/statuses", query: options)
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:



17
18
19
# File 'lib/gitlab/client/commits.rb', line 17

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

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

Creates a new comment for a commit.

Examples:

Gitlab.create_commit_comment(5, 'c9f9662a9b1116c838b523ed64c6abdb4aae4b8b', 'Nice work on this 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:



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

def create_commit_comment(project, commit, note, options={})
  post("/projects/#{project}/repository/commits/#{commit}/comments", body: options.merge(note: note))
end

#update_commit_status(id, sha, state, options = {}) ⇒ Object Also known as: repo_update_commit_status

Adds or updates a status of a commit.

Examples:

Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'success')
Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'failed', name: 'jenkins')
Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'canceled', name: 'jenkins', target_url: 'http://example.com/builds/1')

Parameters:

  • project (Integer)

    The ID of a project.

  • sha (String)

    The commit hash

  • state (String)

    of the status. Can be: pending, running, success, failed, canceled

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

    A customizable set of options.

Options Hash (options):

  • :ref (String)

    The ref (branch or tag) to which the status refers

  • :name (String)

    Filer by status name, eg. jenkins

  • :target_url (String)

    The target URL to associate with this status



116
117
118
# File 'lib/gitlab/client/commits.rb', line 116

def update_commit_status(id, sha, state, options={})
  post("/projects/#{id}/statuses/#{sha}", query: options.merge(state: state))
end