Marks pending tasks for an user as done when he edit a MR

parent 802bf6d0
...@@ -15,6 +15,10 @@ module MergeRequests ...@@ -15,6 +15,10 @@ module MergeRequests
end end
def handle_changes(merge_request, options = {}) def handle_changes(merge_request, options = {})
if have_changes?(merge_request, options)
task_service.mark_as_done(merge_request, current_user)
end
if merge_request.previous_changes.include?('target_branch') if merge_request.previous_changes.include?('target_branch')
create_branch_change_note(merge_request, 'target', create_branch_change_note(merge_request, 'target',
merge_request.previous_changes['target_branch'].first, merge_request.previous_changes['target_branch'].first,
...@@ -44,5 +48,22 @@ module MergeRequests ...@@ -44,5 +48,22 @@ module MergeRequests
def close_service def close_service
MergeRequests::CloseService MergeRequests::CloseService
end end
private
def have_changes?(merge_request, options = {})
valid_attrs = [:title, :description, :assignee_id, :milestone_id, :target_branch]
attrs_changed = valid_attrs.any? do |attr|
merge_request.previous_changes.include?(attr.to_s)
end
old_labels = options[:old_labels]
labels_changed = old_labels && merge_request.labels != old_labels
if attrs_changed || labels_changed
task_service.mark_as_done(merge_request, current_user)
end
end
end end
end end
...@@ -103,11 +103,35 @@ describe MergeRequests::UpdateService, services: true do ...@@ -103,11 +103,35 @@ describe MergeRequests::UpdateService, services: true do
create(:pending_assigned_task, user: user, project: project, target: merge_request, author: user2) create(:pending_assigned_task, user: user, project: project, target: merge_request, author: user2)
end end
context 'when the title change' do
before do
update_merge_request({ title: 'New title' })
end
it 'marks pending tasks as done' do
expect(pending_task.reload).to be_done
end
end
context 'when the description change' do
before do
update_merge_request({ description: 'Also please fix' })
end
it 'marks pending tasks as done' do
expect(pending_task.reload).to be_done
end
end
context 'when is reassigned' do context 'when is reassigned' do
before do before do
update_merge_request({ assignee: user2 }) update_merge_request({ assignee: user2 })
end end
it 'marks previous assignee pending tasks as done' do
expect(pending_task.reload).to be_done
end
it 'creates a pending task for new assignee' do it 'creates a pending task for new assignee' do
attributes = { attributes = {
project: project, project: project,
...@@ -121,6 +145,36 @@ describe MergeRequests::UpdateService, services: true do ...@@ -121,6 +145,36 @@ describe MergeRequests::UpdateService, services: true do
expect(Task.where(attributes).count).to eq 1 expect(Task.where(attributes).count).to eq 1
end end
end end
context 'when the milestone change' do
before do
update_merge_request({ milestone: create(:milestone) })
end
it 'marks pending tasks as done' do
expect(pending_task.reload).to be_done
end
end
context 'when the labels change' do
before do
update_merge_request({ label_ids: [label.id] })
end
it 'marks pending tasks as done' do
expect(pending_task.reload).to be_done
end
end
context 'when the target branch change' do
before do
update_merge_request({ target_branch: 'target' })
end
it 'marks pending tasks as done' do
expect(pending_task.reload).to be_done
end
end
end end
context 'when MergeRequest has tasks' do context 'when MergeRequest has tasks' do
...@@ -155,6 +209,5 @@ describe MergeRequests::UpdateService, services: true do ...@@ -155,6 +209,5 @@ describe MergeRequests::UpdateService, services: true do
end end
end end
end end
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