From 7edf65d1ee9e65e5d5d2bde573936715b46e250d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 10 Jun 2014 12:25:43 +0300 Subject: Make a system comment when issue milestone changed Signed-off-by: Dmitriy Zaporozhets --- app/models/note.rb | 16 ++++++++++++++++ app/services/issues/base_service.rb | 4 ++++ app/services/issues/update_service.rb | 4 ++++ 3 files changed, 24 insertions(+) (limited to 'app') diff --git a/app/models/note.rb b/app/models/note.rb index 278c957af0e..dc8b968c3d2 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -90,6 +90,22 @@ class Note < ActiveRecord::Base create(note_options, without_protection: true) end + def create_milestone_change_note(noteable, project, author, milestone) + body = if milestone.nil? + '_Milestone removed_' + else + "_Milestone changed to #{milestone.title}_" + end + + create({ + noteable: noteable, + project: project, + author: author, + note: body, + system: true + }, without_protection: true) + end + def create_assignee_change_note(noteable, project, author, assignee) body = assignee.nil? ? '_Assignee removed_' : "_Reassigned to @#{assignee.username}_" diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index 2e1e1f7e0f0..eac774210ae 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -10,5 +10,9 @@ module Issues def execute_hooks(issue) issue.project.execute_hooks(issue.to_hook_data, :issue_hooks) end + + def create_milestone_note(issue) + Note.create_milestone_change_note(issue, issue.project, current_user, issue.milestone) + end end end diff --git a/app/services/issues/update_service.rb b/app/services/issues/update_service.rb index b562c401fd4..f69370beddd 100644 --- a/app/services/issues/update_service.rb +++ b/app/services/issues/update_service.rb @@ -13,6 +13,10 @@ module Issues if params.present? && issue.update_attributes(params) issue.reset_events_cache + if issue.previous_changes.include?('milestone_id') + create_milestone_note(issue) + end + if issue.previous_changes.include?('assignee_id') notification_service.reassigned_issue(issue, current_user) create_assignee_note(issue) -- cgit v1.2.1