diff options
Diffstat (limited to 'lib/api/merge_requests.rb')
-rw-r--r-- | lib/api/merge_requests.rb | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 4b88b0f84c1..7fb135b37b8 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -34,7 +34,7 @@ module API when "closed" then user_project.merge_requests.closed when "merged" then user_project.merge_requests.merged else user_project.merge_requests - end + end present paginate(mrs), with: Entities::MergeRequest end @@ -111,6 +111,49 @@ module API end end + # Merge MR + # + # Parameters: + # id (required) - The ID of a project + # merge_request_id (required) - ID of MR + # merge_commit_message (optional) - Custom merge commit message + # Example: + # PUT /projects/:id/merge_request/:merge_request_id/merge + # + put ":id/merge_request/:merge_request_id/merge" do + merge_request = user_project.merge_requests.find(params[:merge_request_id]) + + action = if user_project.protected_branch?(merge_request.target_branch) + :push_code_to_protected_branches + else + :push_code + end + + if can?(current_user, action, user_project) + if merge_request.unchecked? + merge_request.check_if_can_be_merged + end + + if merge_request.open? + if merge_request.can_be_merged? + merge_request.automerge!(current_user, params[:merge_commit_message] || merge_request.merge_commit_message) + present merge_request, with: Entities::MergeRequest + else + render_api_error!('Branch cannot be merged', 405) + end + else + # Merge request can not be merged + # because it is already closed/merged + not_allowed! + end + else + # Merge request can not be merged + # because user dont have permissions to push into target branch + unauthorized! + end + end + + # Get a merge request's comments # # Parameters: |