Commit c4c877e4330feb4684284a067fd0acf4a7a1dfaa

Authored by Dmitriy Zaporozhets
2 parents d2052925 f2353352

Merge branch 'milestone-change-note' into 'master'

Create a note when issue milestone was changed

Part of #1207
app/models/note.rb
@@ -90,6 +90,22 @@ class Note < ActiveRecord::Base @@ -90,6 +90,22 @@ class Note < ActiveRecord::Base
90 create(note_options, without_protection: true) 90 create(note_options, without_protection: true)
91 end 91 end
92 92
  93 + def create_milestone_change_note(noteable, project, author, milestone)
  94 + body = if milestone.nil?
  95 + '_Milestone removed_'
  96 + else
  97 + "_Milestone changed to #{milestone.title}_"
  98 + end
  99 +
  100 + create({
  101 + noteable: noteable,
  102 + project: project,
  103 + author: author,
  104 + note: body,
  105 + system: true
  106 + }, without_protection: true)
  107 + end
  108 +
93 def create_assignee_change_note(noteable, project, author, assignee) 109 def create_assignee_change_note(noteable, project, author, assignee)
94 body = assignee.nil? ? '_Assignee removed_' : "_Reassigned to @#{assignee.username}_" 110 body = assignee.nil? ? '_Assignee removed_' : "_Reassigned to @#{assignee.username}_"
95 111
app/services/issues/base_service.rb
@@ -10,5 +10,9 @@ module Issues @@ -10,5 +10,9 @@ module Issues
10 def execute_hooks(issue) 10 def execute_hooks(issue)
11 issue.project.execute_hooks(issue.to_hook_data, :issue_hooks) 11 issue.project.execute_hooks(issue.to_hook_data, :issue_hooks)
12 end 12 end
  13 +
  14 + def create_milestone_note(issue)
  15 + Note.create_milestone_change_note(issue, issue.project, current_user, issue.milestone)
  16 + end
13 end 17 end
14 end 18 end
app/services/issues/update_service.rb
@@ -13,6 +13,10 @@ module Issues @@ -13,6 +13,10 @@ module Issues
13 if params.present? && issue.update_attributes(params) 13 if params.present? && issue.update_attributes(params)
14 issue.reset_events_cache 14 issue.reset_events_cache
15 15
  16 + if issue.previous_changes.include?('milestone_id')
  17 + create_milestone_note(issue)
  18 + end
  19 +
16 if issue.previous_changes.include?('assignee_id') 20 if issue.previous_changes.include?('assignee_id')
17 notification_service.reassigned_issue(issue, current_user) 21 notification_service.reassigned_issue(issue, current_user)
18 create_assignee_note(issue) 22 create_assignee_note(issue)
app/services/merge_requests/base_service.rb
@@ -16,5 +16,9 @@ module MergeRequests @@ -16,5 +16,9 @@ module MergeRequests
16 merge_request.project.execute_hooks(merge_request.to_hook_data, :merge_request_hooks) 16 merge_request.project.execute_hooks(merge_request.to_hook_data, :merge_request_hooks)
17 end 17 end
18 end 18 end
  19 +
  20 + def create_milestone_note(merge_request)
  21 + Note.create_milestone_change_note(merge_request, merge_request.project, current_user, merge_request.milestone)
  22 + end
19 end 23 end
20 end 24 end
app/services/merge_requests/update_service.rb
@@ -22,6 +22,10 @@ module MergeRequests @@ -22,6 +22,10 @@ module MergeRequests
22 if params.present? && merge_request.update_attributes(params) 22 if params.present? && merge_request.update_attributes(params)
23 merge_request.reset_events_cache 23 merge_request.reset_events_cache
24 24
  25 + if merge_request.previous_changes.include?('milestone_id')
  26 + create_milestone_note(merge_request)
  27 + end
  28 +
25 if merge_request.previous_changes.include?('assignee_id') 29 if merge_request.previous_changes.include?('assignee_id')
26 notification_service.reassigned_merge_request(merge_request, current_user) 30 notification_service.reassigned_merge_request(merge_request, current_user)
27 create_assignee_note(merge_request) 31 create_assignee_note(merge_request)
app/services/notification_service.rb
@@ -254,7 +254,7 @@ class NotificationService @@ -254,7 +254,7 @@ class NotificationService
254 # Remove users with disabled notifications from array 254 # Remove users with disabled notifications from array
255 # Also remove duplications and nil recipients 255 # Also remove duplications and nil recipients
256 def reject_muted_users(users, project = nil) 256 def reject_muted_users(users, project = nil)
257 - users = users.compact.uniq 257 + users = users.to_a.compact.uniq
258 258
259 users.reject do |user| 259 users.reject do |user|
260 next user.notification.disabled? unless project 260 next user.notification.disabled? unless project
spec/features/issues_spec.rb
@@ -248,7 +248,7 @@ describe "Issues", feature: true do @@ -248,7 +248,7 @@ describe "Issues", feature: true do
248 find('.edit-issue.inline-update').select(milestone.title, from: 'issue_milestone_id') 248 find('.edit-issue.inline-update').select(milestone.title, from: 'issue_milestone_id')
249 click_button 'Update Issue' 249 click_button 'Update Issue'
250 250
251 - page.should have_content "Milestone" 251 + page.should have_content "Milestone changed to #{milestone.title}"
252 page.has_select?('issue_assignee_id', :selected => milestone.title) 252 page.has_select?('issue_assignee_id', :selected => milestone.title)
253 end 253 end
254 end 254 end