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, String)

    The ID or name 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/#{url_encode 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/#{url_encode 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, String)

    The ID or name 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/#{url_encode project}/repository/commits/#{sha}/diff")
end

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

Gets a list of merge requests for a commit.

Introduced in Gitlab 10.7

Examples:

Gitlab.commit_merge_requests(5, 'c9f9662a9b1116c838b523ed64c6abdb4aae4b8b')

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

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:

See Also:



159
160
161
# File 'lib/gitlab/client/commits.rb', line 159

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

#commit_status(project, 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, String)

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

    Filter 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(project, sha, options={})
  get("/projects/#{url_encode project}/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, String)

    The ID or name 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/#{url_encode project}/repository/commits", query: options)
end

#create_commit(project, branch, message, actions, options = {}) ⇒ Gitlab::ObjectifiedHash

Creates a single commit with one or more changes

Introduced in Gitlab 8.13

Gitlab.create_commit(2726132, ‘master’, ‘refactors everything’, [‘create’, file_path: ‘/foo.txt’, content: ‘bar’]) Gitlab.create_commit(2726132, ‘master’, ‘refactors everything’, [‘delete’, file_path: ‘/foo.txt’])

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • branch (String)

    the branch name you wish to commit to

  • message (String)

    the commit message

  • An (Array[Hash])

    array of action hashes to commit as a batch. See the next table for what attributes it can take.

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

    a customizable set of options

Options Hash (options):

  • :author_email (String)

    the email address of the author

  • :author_name (String)

    the name of the author

Returns:

See Also:



137
138
139
140
141
142
143
144
# File 'lib/gitlab/client/commits.rb', line 137

def create_commit(project, branch, message, actions, options={})
  payload = {
      branch: branch,
      commit_message: message,
      actions: actions,
  }.merge(options)
  post("/projects/#{url_encode project}/repository/commits", body: payload)
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, String)

    The ID or name 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/#{url_encode project}/repository/commits/#{commit}/comments", body: options.merge(note: note))
end

#update_commit_status(project, 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, String)

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

    Filter 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(project, sha, state, options={})
  post("/projects/#{url_encode project}/statuses/#{sha}", query: options.merge(state: state))
end