1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# frozen_string_literal: true
module API
class MergeRequestApprovals < ::API::Base
before { authenticate_non_get! }
feature_category :source_code_management
helpers ::API::Helpers::MergeRequestsHelpers
helpers do
def present_approval(merge_request)
present merge_request, with: ::API::Entities::MergeRequestApprovals, current_user: current_user
end
end
resource :projects, requirements: ::API::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
segment ':id/merge_requests/:merge_request_iid' do
# Get the status of the merge request's approvals
#
# Parameters:
# id (required) - The ID of a project
# merge_request_iid (required) - IID of MR
# Examples:
# GET /projects/:id/merge_requests/:merge_request_iid/approvals
desc 'List approvals for merge request' do
success ::API::Entities::MergeRequestApprovals
failure [
{ code: 404, message: 'Not found' }
]
end
get 'approvals', urgency: :low do
merge_request = find_merge_request_with_access(params[:merge_request_iid])
present_approval(merge_request)
end
# Approve a merge request
#
# Parameters:
# id (required) - The ID of a project
# merge_request_iid (required) - IID of MR
# Examples:
# POST /projects/:id/merge_requests/:merge_request_iid/approve
#
desc 'Approve a merge request' do
success code: 201, model: ::API::Entities::MergeRequestApprovals
failure [
{ code: 404, message: 'Not found' },
{ code: 401, message: 'Unauthorized' }
]
end
params do
optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch'
use :ee_approval_params
end
post 'approve', urgency: :low do
merge_request = find_merge_request_with_access(params[:merge_request_iid], :approve_merge_request)
check_sha_param!(params, merge_request)
success =
::MergeRequests::ApprovalService
.new(project: user_project, current_user: current_user, params: params)
.execute(merge_request)
unauthorized! unless success
present_approval(merge_request)
end
desc 'Remove an approval from a merge request' do
success code: 201, model: ::API::Entities::MergeRequestApprovals
failure [
{ code: 404, message: 'Not found' },
{ code: 401, message: 'Unauthorized' }
]
end
post 'unapprove', urgency: :low do
merge_request = find_merge_request_with_access(params[:merge_request_iid], :approve_merge_request)
success = ::MergeRequests::RemoveApprovalService
.new(project: user_project, current_user: current_user)
.execute(merge_request)
not_found! unless success
::MergeRequests::UpdateReviewerStateService
.new(project: user_project, current_user: current_user)
.execute(merge_request, "unreviewed")
present_approval(merge_request)
end
desc 'Remove all merge request approvals' do
detail 'Clear all approvals of merge request. This feature was added in GitLab 15.4'
failure [
{ code: 401, message: 'Unauthorized' },
{ code: 404, message: 'Not found' }
]
tags %w[merge_requests]
end
put 'reset_approvals', urgency: :low do
merge_request = find_project_merge_request(params[:merge_request_iid])
unauthorized! unless current_user.can?(:reset_merge_request_approvals, merge_request)
merge_request.approvals.delete_all
status :accepted
end
end
end
end
end
API::MergeRequestApprovals.prepend_mod_with('API::MergeRequestApprovals')
|