Module: Gitlab::Client::MergeRequestApprovals

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

Overview

Defines methods related to MR Approvals.

Instance Method Summary collapse

Instance Method Details

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

Approve a merge request

Examples:

Gitlab.approve_merge_request(1, 5)
Gitlab.approve_merge_request(1, 5, sha: 'fe678da')

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge request.

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

    a customizable set of options

Options Hash (options):

  • :sha(optional) (String)

    The HEAD of the MR

Returns:



236
237
238
# File 'lib/gitlab/client/merge_request_approvals.rb', line 236

def approve_merge_request(project, merge_request, options = {})
  post("/projects/#{url_encode project}/merge_requests/#{merge_request}/approve", body: options)
end

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

Create merge request level rule

Important: When approval_project_rule_id is set, the name, users and groups of project-level rule are copied. The approvals_required specified is used.

Examples:

Gitlab.create_merge_request_level_rule(1, 2, {
  name: "devs",
  approvals_required: 2,
  approval_project_rule_id: 99,
  user_ids: [3, 4],
  group_ids: [5, 6],
})

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge request.

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

    a customizable set of options

Options Hash (options):

  • :name(required) (String)

    The name of the approval rule

  • :approvals_required(required) (Integer)

    The number of required approvals for this rule

  • :approval_project_rule_id(optional) (Integer)

    The ID of a project-level approval rule

  • :user_ids(optional) (Array)

    The ids of users as approvers

  • :group_ids(optional) (Array)

    The ids of groups as approvers

Returns:



168
169
170
# File 'lib/gitlab/client/merge_request_approvals.rb', line 168

def create_merge_request_level_rule(project, merge_request, options = {})
  post("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules", body: options)
end

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

Create MR Approval Rule for a project

Examples:

Gitlab.create_project_merge_request_approval_rule(1, {name: "security", approvals_required: 1})

Parameters:

  • project(required) (Integer)

    The ID of a project.

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

    a customizable set of options

Options Hash (options):

  • :name(required) (String)

    The name of the approval rule

  • :approvals_required(required) (Integer)

    The number of required approvals for this rule

  • :user_ids(optional) (Array)

    The ids of users as approvers

  • :group_ids(optional) (Array)

    The ids of groups as approvers

  • :protected_branch_ids(optional) (Array)

    The ids of protected branches to scope the rule by

Returns:



57
58
59
# File 'lib/gitlab/client/merge_request_approvals.rb', line 57

def create_project_merge_request_approval_rule(project, options = {})
  post("/projects/#{url_encode project}/approval_rules", body: options)
end

#delete_merge_request_level_rule(project, merge_request, appr_rule_id) ⇒ void

This method returns an undefined value.

Delete merge request level rule

Important: Deleting a report_approver or code_owner rule is not allowed. These are system generated rules.

Examples:

Gitlab.delete_merge_request_level_rule(1, 2, 69)

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge request.

  • appr_rule_id(required) (Integer)

    The ID of a approval rule



222
223
224
# File 'lib/gitlab/client/merge_request_approvals.rb', line 222

def delete_merge_request_level_rule(project, merge_request, appr_rule_id)
  delete("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules/#{appr_rule_id}")
end

#delete_project_merge_request_approval_rule(project, approval_rule_id) ⇒ void

This method returns an undefined value.

Delete MR Approval Rule for a project

Examples:

Gitlab.delete_project_merge_request_approval_rule(1, 1)

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • approval_rule_id(required) (Integer)

    The ID of a approval rule



86
87
88
# File 'lib/gitlab/client/merge_request_approvals.rb', line 86

def delete_project_merge_request_approval_rule(project, approval_rule_id)
  delete("/projects/#{url_encode project}/approval_rules/#{approval_rule_id}")
end

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

Change configuration for approvals on a specific merge request.

Examples:

Gitlab.edit_merge_request_approvals(1, 5, approvals_required: 2)

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge_request.

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

    a customizable set of options

Options Hash (options):

  • :approvals_required(required) (Integer)

    Approvals required before MR can be merged

Returns:



126
127
128
# File 'lib/gitlab/client/merge_request_approvals.rb', line 126

def edit_merge_request_approvals(project, merge_request, options = {})
  post("/projects/#{url_encode project}/merge_requests/#{merge_request}/approvals", body: options)
end

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

Deprecated.

Since Gitlab 13.12 /approvers endpoints are removed!!!

Change allowed approvers and approver groups for a merge request See Gitlab.create_merge_request_level_rule

Examples:

Gitlab.edit_merge_request_approvers(1, 5, {approver_ids: [5], approver_groups: [1]})

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge_request.

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

    a customizable set of options

Options Hash (options):

  • :approver_ids(required, (Array)

    nil if none) An array of User IDs that can approve MRs

  • :approver_group_ids(required, (Array)

    nil if none) An array of Group IDs whose members can approve MRs

Returns:



142
143
144
# File 'lib/gitlab/client/merge_request_approvals.rb', line 142

def edit_merge_request_approvers(project, merge_request, options = {})
  put("/projects/#{url_encode project}/merge_requests/#{merge_request}/approvers", body: options)
end

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

Deprecated.

Since Gitlab 13.12 /approvers endpoints are removed!!!

Change allowed approvers and approver groups for a project See Gitlab.create_project_merge_request_approval_rule

Examples:

Gitlab.edit_project_approvers(1, {approver_ids: [5], approver_groups: [1]})

Parameters:

  • project(required) (Integer)

    The ID of a project.

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

    a customizable set of options

Options Hash (options):

  • :approver_ids(required, (Array)

    nil if none) An array of User IDs that can approve MRs

  • :approver_group_ids(required, (Array)

    nil if none) An array of Group IDs whose members can approve MRs

Returns:



101
102
103
# File 'lib/gitlab/client/merge_request_approvals.rb', line 101

def edit_project_approvers(project, options = {})
  put("/projects/#{url_encode project}/approvers", body: options)
end

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

Change MR Approval Configuration for a project

Examples:

Gitlab.edit_project_merge_request_approvals(1, {approvals_before_merge: 3})
Gitlab.edit_project_merge_request_approvals(1, {approvals_before_merge: 3, reset_approvals_on_push: true})
Gitlab.edit_project_merge_request_approvals(1, {approvals_before_merge: 3, disable_overriding_approvers_per_merge_request: false})

Parameters:

  • project(required) (Integer)

    The ID of a project.

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

    a customizable set of options

Options Hash (options):

  • :approvals_before_merge(optional) (Integer)

    How many approvals are required before an MR can be merged

  • :reset_approvals_on_push(optional) (Boolean)

    Reset approvals on a new push

  • :disable_overriding_approvers_per_merge_request(optional) (Boolean)

    Allow/Disallow overriding approvers per MR

Returns:



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

def edit_project_merge_request_approvals(project, options = {})
  post("/projects/#{url_encode project}/approvals", body: options)
end

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

Get the approval state of merge requests

Examples:

Gitlab.merge_request_approval_state(5, 36)

Parameters:

  • project (Integer, String)

    The ID or name of a project.

  • id (Integer)

    The ID of a merge request.

Returns:



261
262
263
# File 'lib/gitlab/client/merge_request_approvals.rb', line 261

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

#merge_request_approvals(project, merge_request) ⇒ Gitlab::ObjectifiedHash

Get Configuration for approvals on a specific Merge Request.

Examples:

Gitlab.merge_request_approvals(1, 5)

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge_request.

Returns:



113
114
115
# File 'lib/gitlab/client/merge_request_approvals.rb', line 113

def merge_request_approvals(project, merge_request)
  get("/projects/#{url_encode project}/merge_requests/#{merge_request}/approvals")
end

#merge_request_level_rule(project, merge_request) ⇒ Gitlab::ObjectifiedHash

Get merge request level rule

Examples:

Gitlab.merge_request_level_rule(1, 2)

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge request.

Returns:



180
181
182
# File 'lib/gitlab/client/merge_request_approvals.rb', line 180

def merge_request_level_rule(project, merge_request)
  get("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules")
end

#project_merge_request_approval_rules(project) ⇒ Gitlab::ObjectifiedHash

Gets MR Approval Rules for a project

Examples:

Gitlab.project_merge_request_approval_rules(1)

Parameters:

  • project (Integer)

    The ID of a project.

Returns:



41
42
43
# File 'lib/gitlab/client/merge_request_approvals.rb', line 41

def project_merge_request_approval_rules(project)
  get("/projects/#{url_encode project}/approval_rules")
end

#project_merge_request_approvals(project) ⇒ Gitlab::ObjectifiedHash

Gets MR Approval Configuration for a project

Examples:

Gitlab.project_merge_request_approvals(1)

Parameters:

  • project (Integer)

    The ID of a project.

Returns:



14
15
16
# File 'lib/gitlab/client/merge_request_approvals.rb', line 14

def project_merge_request_approvals(project)
  get("/projects/#{url_encode project}/approvals")
end

#unapprove_merge_request(project, merge_request, options = {}) ⇒ void

This method returns an undefined value.

Unapprove a merge request

Examples:

Gitlab.unapprove_merge_request(1, 5)

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge request.

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

    a customizable set of options

Options Hash (options):

  • :sudo(optional) (String)

    The username of the user you want to remove the approval for



249
250
251
# File 'lib/gitlab/client/merge_request_approvals.rb', line 249

def unapprove_merge_request(project, merge_request, options = {})
  post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove", body: options)
end

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

Update merge request level rule

Important: Approvers and groups not in the users/groups parameters are removed Important: Updating a report_approver or code_owner rule is not allowed. These are system generated rules.

Examples:

Gitlab.update_merge_request_level_rule(1, 2, 69, {
  name: "devs",
  approvals_required: 2,
  user_ids: [3, 4],
  group_ids: [5, 6],
})

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • merge_request(required) (Integer)

    The IID of a merge request.

  • appr_rule_id(required) (Integer)

    The ID of a approval rule

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

    a customizable set of options

Options Hash (options):

  • :name(required) (String)

    The name of the approval rule

  • :approvals_required(required) (Integer)

    The number of required approvals for this rule

  • :user_ids(optional) (Array)

    The ids of users as approvers

  • :group_ids(optional) (Array)

    The ids of groups as approvers

Returns:



206
207
208
# File 'lib/gitlab/client/merge_request_approvals.rb', line 206

def update_merge_request_level_rule(project, merge_request, appr_rule_id, options = {})
  put("/projects/#{url_encode project}/merge_requests/#{merge_request}/approval_rules/#{appr_rule_id}", body: options)
end

#update_project_merge_request_approval_rule(project, approval_rule_id, options = {}) ⇒ Gitlab::ObjectifiedHash

Update MR Approval Rule for a project

Examples:

Gitlab.update_project_merge_request_approval_rule(1, {name: "security", approvals_required: 2})

Parameters:

  • project(required) (Integer)

    The ID of a project.

  • approval_rule_id(required) (Integer)

    The ID of a project Approval Rule

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

    a customizable set of options

Options Hash (options):

  • :name(required) (String)

    The name of the approval rule

  • :approvals_required(required) (Integer)

    The number of required approvals for this rule

  • :user_ids(optional) (Array)

    The ids of users as approvers

  • :group_ids(optional) (Array)

    The ids of groups as approvers

  • :protected_branch_ids(optional) (Array)

    The ids of protected branches to scope the rule by

Returns:



74
75
76
# File 'lib/gitlab/client/merge_request_approvals.rb', line 74

def update_project_merge_request_approval_rule(project, approval_rule_id, options = {})
  put("/projects/#{url_encode project}/approval_rules/#{approval_rule_id}", body: options)
end