Commit a581942a authored by Jarka Košanová's avatar Jarka Košanová

Create system notes for epic close and reopen

parent e11f5a61
......@@ -212,7 +212,7 @@ module SystemNoteService
# "closed via bc17db76"
#
# Returns the created Note object
def change_status(noteable, project, author, status, source)
def change_status(noteable, project, author, status, source = nil)
body = status.dup
body << " via #{source.gfm_reference(project)}" if source
......
......@@ -13,6 +13,7 @@ module Epics
def close_epic(epic)
if epic.close
epic.update(closed_by: current_user)
SystemNoteService.change_status(epic, nil, current_user, epic.state)
end
end
end
......
......@@ -5,8 +5,15 @@ module Epics
def execute(epic)
return epic unless can?(current_user, :update_epic, epic)
epic.reopen
epic
reopen_epic(epic)
end
private
def reopen_epic(epic)
if epic.reopen
SystemNoteService.change_status(epic, nil, current_user, epic.state)
end
end
end
end
---
title: Create system notes for epic close and reopen
merge_request: 7850
author:
type: added
......@@ -41,6 +41,15 @@ describe Epics::CloseService do
it 'changes closed_at' do
expect { subject.execute(epic) }.to change { epic.closed_at }
end
it 'creates a system note about epic close' do
expect { subject.execute(epic) }.to change { epic.notes.count }.by(1)
note = epic.notes.last
expect(note.note).to eq('closed')
expect(note.system_note_metadata.action).to eq('closed')
end
end
context 'when trying to close a closed epic' do
......@@ -59,6 +68,10 @@ describe Epics::CloseService do
it 'does not change closed_by' do
expect { subject.execute(epic) }.not_to change { epic.closed_by }
end
it 'does not create a system note' do
expect { subject.execute(epic) }.not_to change { epic.notes.count }
end
end
end
......
......@@ -41,6 +41,15 @@ describe Epics::ReopenService do
it 'removes closed_at' do
expect { subject.execute(epic) }.to change { epic.closed_at }.to(nil)
end
it 'creates a system note about epic reopen' do
expect { subject.execute(epic) }.to change { epic.notes.count }.by(1)
note = epic.notes.last
expect(note.note).to eq('opened')
expect(note.system_note_metadata.action).to eq('opened')
end
end
context 'when trying to reopen an opened epic' do
......@@ -59,6 +68,10 @@ describe Epics::ReopenService do
it 'does not change closed_by' do
expect { subject.execute(epic) }.not_to change { epic.closed_by }
end
it 'does not create a system note' do
expect { subject.execute(epic) }.not_to change { epic.notes.count }
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