Commit 80e30a92 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add system note when user approves merge request

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 07703c22
......@@ -200,7 +200,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def approve
@approval = @merge_request.approvals.new
@approval.user = current_user
@approval.save
if @approval.save
SystemNoteService.approve_mr(@merge_request, current_user)
end
redirect_to merge_request_path(@merge_request)
end
......
......@@ -255,6 +255,22 @@ class SystemNoteService
notes.count > 0
end
# Called when the merge request is approved by user
#
# noteable - Noteable object
# user - User performing approve
#
# Example Note text:
#
# "Approved by @rspeicher"
#
# Returns the created Note object
def self.approve_mr(noteable, user)
body = "Approved by @#{user.username}"
create_note(noteable: noteable, project: noteable.project, author: user, note: body)
end
private
def self.create_note(args = {})
......
......@@ -442,4 +442,17 @@ describe SystemNoteService do
end
end
end
describe '.approve_mr' do
let(:noteable) { create(:merge_request, source_project: project) }
subject { described_class.approve_mr(noteable, author) }
it_behaves_like 'a system note'
context 'when assignee added' do
it 'sets the note text' do
expect(subject.note).to eq "Approved by @#{author.username}"
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment