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

#cherry_pick_commit(project, sha, branch) ⇒ Gitlab::ObjectifiedHash

Cherry picks a commit to a given branch.

Examples:

Gitlab.cherry_pick_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • sha (String)

    The commit hash or name of a repository branch or tag

  • branch (String)

    The name of the branch

Returns:


63
64
65
# File 'lib/gitlab/client/commits.rb', line 63

def cherry_pick_commit(project, sha, branch)
  post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: { branch: branch })
end

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


33
34
35
# File 'lib/gitlab/client/commits.rb', line 33

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:


91
92
93
# File 'lib/gitlab/client/commits.rb', line 91

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:


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

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:


190
191
192
# File 'lib/gitlab/client/commits.rb', line 190

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

#commit_refs(project, sha, options = {}) ⇒ Gitlab::ObjectifiedHash

Get all references (from branches or tags) a commit is pushed to.

Examples:

Gitlab.commit_refs(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')

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

  • :type (String)

    The scope of commits. Possible values `branch`, `tag`, `all`. Default is `all`.

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:


50
51
52
# File 'lib/gitlab/client/commits.rb', line 50

def commit_refs(project, sha, options = {})
  get("/projects/#{url_encode project}/repository/commits/#{sha}/refs", 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


128
129
130
# File 'lib/gitlab/client/commits.rb', line 128

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:


19
20
21
# File 'lib/gitlab/client/commits.rb', line 19

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:


168
169
170
171
172
173
174
175
# File 'lib/gitlab/client/commits.rb', line 168

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:


109
110
111
# File 'lib/gitlab/client/commits.rb', line 109

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


147
148
149
# File 'lib/gitlab/client/commits.rb', line 147

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