debian-mirror-gitlab/lib/api/merge_request_approvals.rb

97 lines
3.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module API
2021-01-03 14:25:43 +05:30
class MergeRequestApprovals < ::API::Base
2020-07-28 23:09:34 +05:30
before { authenticate_non_get! }
2021-02-22 17:27:13 +05:30
feature_category :source_code_management
2021-01-29 00:20:46 +05:30
2023-01-13 00:05:48 +05:30
helpers ::API::Helpers::MergeRequestsHelpers
2020-07-28 23:09:34 +05:30
2023-01-13 00:05:48 +05:30
helpers do
2020-07-28 23:09:34 +05:30
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
2023-01-13 00:05:48 +05:30
desc 'List approvals for merge request' do
success ::API::Entities::MergeRequestApprovals
failure [
{ code: 404, message: 'Not found' }
]
end
2021-12-07 22:27:20 +05:30
get 'approvals', urgency: :low do
2020-07-28 23:09:34 +05:30
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
#
2023-01-13 00:05:48 +05:30
desc 'Approve a merge request' do
success code: 201, model: ::API::Entities::MergeRequestApprovals
failure [
{ code: 404, message: 'Not found' },
{ code: 401, message: 'Unauthorized' }
]
end
2020-07-28 23:09:34 +05:30
params do
optional :sha, type: String, desc: 'When present, must have the HEAD SHA of the source branch'
use :ee_approval_params
end
2021-12-11 22:18:48 +05:30
post 'approve', urgency: :low do
2020-07-28 23:09:34 +05:30
merge_request = find_merge_request_with_access(params[:merge_request_iid], :approve_merge_request)
check_sha_param!(params, merge_request)
success =
::MergeRequests::ApprovalService
2021-06-08 01:23:25 +05:30
.new(project: user_project, current_user: current_user, params: params)
2020-07-28 23:09:34 +05:30
.execute(merge_request)
unauthorized! unless success
present_approval(merge_request)
end
2023-01-13 00:05:48 +05:30
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
2021-12-11 22:18:48 +05:30
post 'unapprove', urgency: :low do
2020-07-28 23:09:34 +05:30
merge_request = find_merge_request_with_access(params[:merge_request_iid], :approve_merge_request)
success = ::MergeRequests::RemoveApprovalService
2021-06-08 01:23:25 +05:30
.new(project: user_project, current_user: current_user)
2020-07-28 23:09:34 +05:30
.execute(merge_request)
not_found! unless success
present_approval(merge_request)
end
end
end
end
end
2021-06-08 01:23:25 +05:30
API::MergeRequestApprovals.prepend_mod_with('API::MergeRequestApprovals')