diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 67f3fb51..a980fac6 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -25,7 +25,7 @@ class MergeRequest < ActiveRecord::Base include Issuable attr_accessible :title, :assignee_id, :target_branch, :source_branch, :milestone_id, - :author_id_of_changes + :author_id_of_changes, :state_event attr_accessor :should_remove_source_branch diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2cd8aa6c..8d965b60 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -81,7 +81,7 @@ module Gitlab end class MergeRequest < Grape::Entity - expose :id, :target_branch, :source_branch, :project_id, :title, :closed, :merged + expose :id, :target_branch, :source_branch, :project_id, :title, :state expose :author, :assignee, using: Entities::UserBasic end diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 470cd1e1..7f763eb4 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -73,12 +73,12 @@ module Gitlab # target_branch - The target branch # assignee_id - Assignee user ID # title - Title of MR - # closed - Status of MR. true - closed + # state_event - Status of MR. (close|reopen|merge) # Example: # PUT /projects/:id/merge_request/:merge_request_id # put ":id/merge_request/:merge_request_id" do - attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :closed] + attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :state_event] merge_request = user_project.merge_requests.find(params[:merge_request_id]) authorize! :modify_merge_request, merge_request diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 5da54154..1abd7a20 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -43,6 +43,23 @@ describe Gitlab::API do end end + describe "PUT /projects/:id/merge_request/:merge_request_id to close MR" do + it "should return merge_request" do + put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), state_event: "close" + response.status.should == 200 + json_response['state'].should == 'closed' + end + end + + describe "PUT /projects/:id/merge_request/:merge_request_id to merge MR" do + it "should return merge_request" do + put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), state_event: "merge" + response.status.should == 200 + json_response['state'].should == 'merged' + end + end + + describe "PUT /projects/:id/merge_request/:merge_request_id" do it "should return merge_request" do put api("/projects/#{project.id}/merge_request/#{merge_request.id}", user), title: "New title"