Module: Gitlab::Client::MergeRequests

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

Overview

Defines methods related to merge requests.

Instance Method Summary collapse

Instance Method Details

#accept_merge_request(project, id, options = {}) ⇒ Gitlab::ObjectifiedHash

Accepts a merge request.

Examples:

Gitlab.accept_merge_request(5, 42, { merge_commit_message: 'Nice!' })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

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

    A customizable set of options.

Options Hash (options):

  • :merge_commit_message(optional) (String)

    Custom merge commit message

  • :squash_commit_message(optional) (String)

    Custom squash commit message

  • :squash(optional) (Boolean)

    if true the commits will be squashed into a single commit on merge

  • :should_remove_source_branch(optional) (Boolean)

    if true removes the source branch

  • :merge_when_pipeline_succeeds(optional) (Boolean)

    if true the MR is merged when the pipeline succeeds

  • :sha(optional) (String)

    if present, then this SHA must match the HEAD of the source branch, otherwise the merge will fail

Returns:



154
155
156
# File 'lib/gitlab/client/merge_requests.rb', line 154

def accept_merge_request(project, id, options = {})
  put("/projects/#{url_encode project}/merge_requests/#{id}/merge", body: options)
end

#create_merge_request(project, title, options = {}) ⇒ Gitlab::ObjectifiedHash

Creates a merge request.

Examples:

Gitlab.create_merge_request(5, 'New merge request',
  { source_branch: 'source_branch', target_branch: 'target_branch' })
Gitlab.create_merge_request(5, 'New merge request',
  { source_branch: 'source_branch', target_branch: 'target_branch', assignee_id: 42 })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • title (String)

    The title of a merge request.

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

    A customizable set of options.

Options Hash (options):

  • :source_branch (String) — default: required

    The source branch name.

  • :target_branch (String) — default: required

    The target branch name.

  • :assignee_id (Integer) — default: optional

    The ID of a user to assign merge request.

  • :assignee_ids (Array<Integer>) — default: optional

    The ID of the user(s) to assign the MR to. Set to 0 or provide an empty value to unassign all assignees.

  • :description (String) — default: optional

    Description of MR. Limited to 1,048,576 characters.

  • :target_project_id (Integer) — default: optional

    The target project ID.

  • :labels (String) — default: optional

    Labels as a comma-separated list.

  • :milestone_id (Integer) — default: optional

    The global ID of a milestone

  • :remove_source_branch (Boolean) — default: optional

    Flag indicating if a merge request should remove the source branch when merging

  • :allow_collaboration (Boolean) — default: optional

    Allow commits from members who can merge to the target branch

  • :squash (Boolean) — default: optional

    Squash commits into a single commit when merging

Returns:



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

def create_merge_request(project, title, options = {})
  body = { title: title }.merge(options)
  post("/projects/#{url_encode project}/merge_requests", body: body)
end

#create_merge_request_discussion(project, merge_request_id, options = {}) ⇒ Gitlab::ObjectifiedHash

Create new merge request discussion

Examples:

Gitlab.create_merge_request_discussion(5, 1, body: 'discuss')
Gitlab.create_merge_request_discussion('gitlab', 1, body: 'discuss')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

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

    A customizable set of options.

    • :body (String) The content of a discussion

    • :created_at (String) Date time string, ISO 8601 formatted, e.g. 2016-03-11T03:45:40Z

    • :position (Hash) Position when creating a diff note

      • :base_sha (String) Base commit SHA in the source branch

      • :start_sha (String) SHA referencing commit in target branch

      • :head_sha (String) SHA referencing HEAD of this merge request

      • :position_type (String) Type of the position reference’, allowed values: ‘text’ or ‘image’

      • :new_path (String) File path after change

      • :new_line (Integer) Line number after change (for ‘text’ diff notes)

      • :old_path (String) File path before change

      • :old_line (Integer) Line number before change (for ‘text’ diff notes)

      • :width (Integer) Width of the image (for ‘image’ diff notes)

      • :height (Integer) Height of the image (for ‘image’ diff notes)

      • :x (Integer) X coordinate (for ‘image’ diff notes)

      • :y (Integer) Y coordinate (for ‘image’ diff notes)

Returns:



268
269
270
# File 'lib/gitlab/client/merge_requests.rb', line 268

def create_merge_request_discussion(project, merge_request_id, options = {})
  post("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions", body: options)
end

#create_merge_request_discussion_note(project, merge_request_id, discussion_id, options) ⇒ Gitlab::ObjectifiedHash

Add note to existing merge request discussion

Examples:

Gitlab.create_merge_request_discussion_note(5, 1, 1, note_id: 1, body: 'note')
Gitlab.create_merge_request_discussion_note('gitlab', 1, 1, note_id: 1, body: 'note')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

  • discussion_id (Integer)

    The ID of a discussion.

  • options (Hash)

    A customizable set of options.

Options Hash (options):

  • :note_id (Integer)

    The ID of a discussion note.

  • :body (String)

    The content of a discussion.

  • :created_at (String)

    Date time string, ISO 8601 formatted, e.g. 2016-03-11T03:45:40Z.

Returns:



300
301
302
# File 'lib/gitlab/client/merge_requests.rb', line 300

def create_merge_request_discussion_note(project, merge_request_id, discussion_id, options)
  post("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes", body: options)
end

#create_merge_request_pipeline(project, iid) ⇒ Gitlab::ObjectifiedHash

Create a new pipeline for a merge request. A pipeline created via this endpoint doesnt run a regular branch/tag pipeline. It requires .gitlab-ci.yml to be configured with only: [merge_requests] to create jobs.

The new pipeline can be:

A detached merge request pipeline. A pipeline for merged results if the project setting is enabled.

Examples:

Gitlab.create_merge_request_pipeline(5, 36)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • iid (Integer)

    The internal ID of a merge request.

Returns:



77
78
79
# File 'lib/gitlab/client/merge_requests.rb', line 77

def create_merge_request_pipeline(project, iid)
  post("/projects/#{url_encode project}/merge_requests/#{iid}/pipelines")
end

#delete_merge_request_discussion_note(project, merge_request_id, discussion_id, note_id) ⇒ Gitlab::ObjectifiedHash

Delete a merge request discussion note

Examples:

Gitlab.delete_merge_request_discussion_note(5, 1, 1, 1)
Gitlab.delete_merge_request_discussion_note('gitlab', 1, 1, 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

  • discussion_id (Integer)

    The ID of a discussion.

  • note_id (Integer)

    The ID of a discussion note.

Returns:



331
332
333
# File 'lib/gitlab/client/merge_requests.rb', line 331

def delete_merge_request_discussion_note(project, merge_request_id, discussion_id, note_id)
  delete("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes/#{note_id}")
end

#merge_request(project, id, options = {}) ⇒ Gitlab::ObjectifiedHash

Gets a single merge request.

Examples:

Gitlab.merge_request(5, 36)
Gitlab.merge_request(5, 36, { include_diverged_commits_count: true })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

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

    a customizable set of options

Options Hash (options):

  • :render_html (Boolean)

    If true response includes rendered HTML for title and description.

  • :include_diverged_commits_count (Boolean)

    If true response includes the commits behind the target branch.

  • :include_rebase_in_progress (Boolean)

    If true response includes whether a rebase operation is in progress.

Returns:



46
47
48
# File 'lib/gitlab/client/merge_requests.rb', line 46

def merge_request(project, id, options = {})
  get("/projects/#{url_encode project}/merge_requests/#{id}", query: options)
end

#merge_request_changes(project, id) ⇒ Gitlab::ObjectifiedHash

Gets the changes of a merge request.

Examples:

Gitlab.merge_request_changes(5, 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



166
167
168
# File 'lib/gitlab/client/merge_requests.rb', line 166

def merge_request_changes(project, id)
  get("/projects/#{url_encode project}/merge_requests/#{id}/changes")
end

#merge_request_closes_issues(project_id, merge_request_iid) ⇒ Object

List issues that will close on merge

Examples:

Gitlab.merge_request_closes_issues(5, 1)

Parameters:

  • project (Integer)

    The ID of a project

  • iid (Integer)

    The internal ID of a merge request



189
190
191
# File 'lib/gitlab/client/merge_requests.rb', line 189

def merge_request_closes_issues(project_id, merge_request_iid)
  get("/projects/#{url_encode project_id}/merge_requests/#{merge_request_iid}/closes_issues")
end

#merge_request_commits(project, id) ⇒ Array<Gitlab::ObjectifiedHash>

Gets the commits of a merge request.

Examples:

Gitlab.merge_request_commits(5, 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



178
179
180
# File 'lib/gitlab/client/merge_requests.rb', line 178

def merge_request_commits(project, id)
  get("/projects/#{url_encode project}/merge_requests/#{id}/commits")
end

#merge_request_diff_version(project, merge_request_id, version_id) ⇒ Gitlab::ObjectifiedHash

Gets the diff a single merge request diff version\

Examples:

Gitlab.merge_request_diff_version(5, 1, 1)
Gitlab.merge_request_diff_version('gitlab', 1, 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

  • id (Integer)

    The ID of a merge request diff version.

Returns:



356
357
358
# File 'lib/gitlab/client/merge_requests.rb', line 356

def merge_request_diff_version(project, merge_request_id, version_id)
  get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions/#{version_id}")
end

#merge_request_diff_versions(project, merge_request_id) ⇒ Gitlab::ObjectifiedHash

Gets a list of merge request diff versions

Examples:

Gitlab.merge_request_versions(5, 1)
Gitlab.merge_request_versions('gitlab', 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



343
344
345
# File 'lib/gitlab/client/merge_requests.rb', line 343

def merge_request_diff_versions(project, merge_request_id)
  get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/versions")
end

#merge_request_discussion(project, merge_request_id, discussion_id) ⇒ Gitlab::ObjectifiedHash

Get single merge request discussion

Examples:

Gitlab.merge_request_discussion(5, 1, 1)
Gitlab.merge_request_discussion('gitlab', 1, 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

  • discussion_id (Integer)

    The ID of a discussion.

Returns:



240
241
242
# File 'lib/gitlab/client/merge_requests.rb', line 240

def merge_request_discussion(project, merge_request_id, discussion_id)
  get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}")
end

#merge_request_discussions(project, merge_request_id) ⇒ Gitlab::ObjectifiedHash

List project merge request discussions

Examples:

Gitlab.merge_request_discussions(5, 1)
Gitlab.merge_request_discussions('gitlab', 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



227
228
229
# File 'lib/gitlab/client/merge_requests.rb', line 227

def merge_request_discussions(project, merge_request_id)
  get("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions")
end

#merge_request_participants(project, id) ⇒ Array<Gitlab::ObjectifiedHash>

Get a list of merge request participants.

Examples:

Gitlab.merge_request_participants(5, 36)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



89
90
91
# File 'lib/gitlab/client/merge_requests.rb', line 89

def merge_request_participants(project, id)
  get("/projects/#{url_encode project}/merge_requests/#{id}/participants")
end

#merge_request_pipelines(project, id) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of merge request pipelines.

Examples:

Gitlab.merge_request_pipelines(5, 36)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



58
59
60
# File 'lib/gitlab/client/merge_requests.rb', line 58

def merge_request_pipelines(project, id)
  get("/projects/#{url_encode project}/merge_requests/#{id}/pipelines")
end

#merge_requests(project, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of project merge requests.

Examples:

Gitlab.merge_requests(5)
Gitlab.merge_requests(5, { per_page: 40 })

Parameters:

  • project (Integer, String)

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



30
31
32
# File 'lib/gitlab/client/merge_requests.rb', line 30

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

#rebase_merge_request(project, id, options = {}) ⇒ Gitlab::ObjectifiedHash

Rebase a merge request.

Examples:

Gitlab.rebase_merge_request(5, 42, { skip_ci: true })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

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

    A customizable set of options.

Options Hash (options):

  • :skip_ci (String)

    Set to true to skip creating a CI pipeline

Returns:



370
371
372
# File 'lib/gitlab/client/merge_requests.rb', line 370

def rebase_merge_request(project, id, options = {})
  put("/projects/#{url_encode project}/merge_requests/#{id}/rebase", body: options)
end

#resolve_merge_request_discussion(project, merge_request_id, discussion_id, options) ⇒ Gitlab::ObjectifiedHash

Resolve a merge request discussion

Examples:

Gitlab.resolve_merge_request_discussion(5, 1, 1, true)
Gitlab.resolve_merge_request_discussion('gitlab', 1, 1, false)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

  • discussion_id (Integer)

    The ID of a discussion.

  • options (Hash)

    A customizable set of options.

Options Hash (options):

  • :resolved (Boolean)

    Resolve/unresolve the discussion.

Returns:



283
284
285
# File 'lib/gitlab/client/merge_requests.rb', line 283

def resolve_merge_request_discussion(project, merge_request_id, discussion_id, options)
  put("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}", body: options)
end

#subscribe_to_merge_request(project, id) ⇒ Gitlab::ObjectifiedHash

Subscribes to a merge request.

Examples:

Gitlab.subscribe_to_merge_request(5, 1)
Gitlab.subscribe_to_merge_request('gitlab', 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



202
203
204
# File 'lib/gitlab/client/merge_requests.rb', line 202

def subscribe_to_merge_request(project, id)
  post("/projects/#{url_encode project}/merge_requests/#{id}/subscribe")
end

#unsubscribe_from_merge_request(project, id) ⇒ Gitlab::ObjectifiedHash

Unsubscribes from a merge request.

Examples:

Gitlab.unsubscribe_from_merge_request(5, 1)
Gitlab.unsubscribe_from_merge_request('gitlab', 1)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



215
216
217
# File 'lib/gitlab/client/merge_requests.rb', line 215

def unsubscribe_from_merge_request(project, id)
  post("/projects/#{url_encode project}/merge_requests/#{id}/unsubscribe")
end

#update_merge_request(project, id, options = {}) ⇒ Gitlab::ObjectifiedHash

Updates a merge request.

Examples:

Gitlab.update_merge_request(5, 42, { title: 'New title' })

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

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

    A customizable set of options.

Options Hash (options):

  • :title (String)

    The title of a merge request.

  • :source_branch (String)

    The source branch name.

  • :target_branch (String)

    The target branch name.

  • :assignee_id (Integer)

    The ID of a user to assign merge request.

  • :state_event (String)

    New state (close|reopen|merge).

Returns:



135
136
137
# File 'lib/gitlab/client/merge_requests.rb', line 135

def update_merge_request(project, id, options = {})
  put("/projects/#{url_encode project}/merge_requests/#{id}", body: options)
end

#update_merge_request_discussion_note(project, merge_request_id, discussion_id, note_id, options) ⇒ Gitlab::ObjectifiedHash

Modify an existing merge request discussion note

Examples:

Gitlab.update_merge_request_discussion_note(5, 1, 1, 1, body: 'note')
Gitlab.update_merge_request_discussion_note('gitlab', 1, 1, 1, body: 'note')

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

  • discussion_id (Integer)

    The ID of a discussion.

  • note_id (Integer)

    The ID of a discussion note.

  • options (Hash)

    A customizable set of options.

Options Hash (options):

  • :body (String)

    The content of a discussion.

  • :resolved (Boolean)

    Resolve/unresolve the note.

Returns:



317
318
319
# File 'lib/gitlab/client/merge_requests.rb', line 317

def update_merge_request_discussion_note(project, merge_request_id, discussion_id, note_id, options)
  put("/projects/#{url_encode project}/merge_requests/#{merge_request_id}/discussions/#{discussion_id}/notes/#{note_id}", body: options)
end

#user_merge_requests(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of all of the merge requests the authenticated user has access to.

Examples:

Gitlab.user_merge_requests
Gitlab.user_merge_requests(state: :opened, scope: :all)

Parameters:

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

    A customizable set of options.

Returns:



15
16
17
# File 'lib/gitlab/client/merge_requests.rb', line 15

def user_merge_requests(options = {})
  get('/merge_requests', query: options)
end