diff options
author | Stan Hu <stanhu@gmail.com> | 2015-10-09 09:14:35 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-10-10 10:59:02 -0700 |
commit | 2df573dac3859034fcb90566a8ebc270a7e6088a (patch) | |
tree | d3d344939b9cf8c50908ac87f1bdce3b7a1d316b | |
parent | c99e9edce7fa71ad53cb35e3bac2afe4646d1ebd (diff) | |
download | gitlab-ce-2df573dac3859034fcb90566a8ebc270a7e6088a.tar.gz |
Fix bug where merge request comments created by API would not trigger notifications
Closes https://github.com/gitlabhq/gitlabhq/issues/9715
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | lib/api/merge_requests.rb | 12 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 5 |
3 files changed, 16 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG index f9a4d17fa16..e7e7e7becfd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.1.0 (unreleased) - Make diff file view easier to use on mobile screens (Stan Hu) + - Fix bug where merge request comments created by API would not trigger notifications (Stan Hu) - Add support for creating directories from Files page (Stan Hu) - Allow removing of project without confirmation when JavaScript is disabled (Stan Hu) - Support filtering by "Any" milestone or issue and fix "No Milestone" and "No Label" filters (Stan Hu) diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb index 63ea2f05438..8cfc8ee6713 100644 --- a/lib/api/merge_requests.rb +++ b/lib/api/merge_requests.rb @@ -249,8 +249,16 @@ module API required_attributes! [:note] merge_request = user_project.merge_requests.find(params[:merge_request_id]) - note = merge_request.notes.new(note: params[:note], project_id: user_project.id) - note.author = current_user + + authorize! :create_note, merge_request + + opts = { + note: params[:note], + noteable_type: 'MergeRequest', + noteable_id: merge_request.id + } + + note = ::Notes::CreateService.new(user_project, current_user, opts).execute if note.save present note, with: Entities::MRNote diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 35b3d3e296a..a68c7b1e461 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -379,9 +379,14 @@ describe API::API, api: true do describe "POST /projects/:id/merge_request/:merge_request_id/comments" do it "should return comment" do + original_count = merge_request.notes.size + post api("/projects/#{project.id}/merge_request/#{merge_request.id}/comments", user), note: "My comment" expect(response.status).to eq(201) expect(json_response['note']).to eq('My comment') + expect(json_response['author']['name']).to eq(user.name) + expect(json_response['author']['username']).to eq(user.username) + expect(merge_request.notes.size).to eq(original_count + 1) end it "should return 400 if note is missing" do |