summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-13 11:27:19 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-05-13 11:27:19 +0000
commit0c621708658da4b3cf88d805da5dbad920f3d27f (patch)
tree99ae5d61a368da3cc7f1470d135f5c1aa2a2751c /lib
parent17858d49f6b189c922c7a69e94b5d8aa96fb48ad (diff)
parent2d2b2da45a586bdf29e115dcb4b4f66f9a1feed0 (diff)
downloadgitlab-ce-0c621708658da4b3cf88d805da5dbad920f3d27f.tar.gz
Merge branch 'api-mr-merge' into 'master'
Accept merge request API This MR adds new endpoint `PUT /projects/:id/merge_request/:merge_request_id/merge`. After this change you can merge branches using API. Fixes internal issue #1166
Diffstat (limited to 'lib')
-rw-r--r--lib/api/merge_requests.rb45
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: