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:


152
153
154
# File 'lib/gitlab/client/merge_request_approvals.rb', line 152

def approve_merge_request(project, merge_request, options = {})
  post("/projects/#{url_encode project}/merge_requests/#{merge_request}/approve", 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_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:


124
125
126
# File 'lib/gitlab/client/merge_request_approvals.rb', line 124

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

Change allowed approvers and approver groups for a merge request

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:


138
139
140
# File 'lib/gitlab/client/merge_request_approvals.rb', line 138

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

Change allowed approvers and approver groups for a project

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:


99
100
101
# File 'lib/gitlab/client/merge_request_approvals.rb', line 99

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:


177
178
179
# File 'lib/gitlab/client/merge_request_approvals.rb', line 177

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:


111
112
113
# File 'lib/gitlab/client/merge_request_approvals.rb', line 111

def merge_request_approvals(project, merge_request)
  get("/projects/#{url_encode project}/merge_requests/#{merge_request}/approvals")
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


165
166
167
# File 'lib/gitlab/client/merge_request_approvals.rb', line 165

def unapprove_merge_request(project, merge_request, options = {})
  post("/projects/#{url_encode project}/merge_requests/#{merge_request}/unapprove", 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