Commit dde96231 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'mr_api_todo_close' into 'master'

Closes todos for a merge request when the MR is accepted via the API by the MR assignee.

## Are there points in the code the reviewer needs to double check?

Please review refresh service test changes to see if they are correct - I think in those cases, the todos should actually be cleared instead of left pending.

## Why was this MR needed?

To make the API behavior consistent with the UI behavior (accepting your own MRs closes the todo item and prevents them from piling up).

Closes #22477

See merge request !6486
parents db00b495 6d49fcf4
...@@ -20,6 +20,7 @@ v 8.13.0 (unreleased) ...@@ -20,6 +20,7 @@ v 8.13.0 (unreleased)
- Optimize GitHub importing for speed and memory - Optimize GitHub importing for speed and memory
- API: expose pipeline data in builds API (!6502, Guilherme Salazar) - API: expose pipeline data in builds API (!6502, Guilherme Salazar)
- Fix broken repository 500 errors in project list - Fix broken repository 500 errors in project list
- Close todos when accepting merge requests via the API !6486 (tonygambone)
v 8.12.4 (unreleased) v 8.12.4 (unreleased)
......
...@@ -308,8 +308,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -308,8 +308,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController
return return
end end
TodoService.new.merge_merge_request(merge_request, current_user)
@merge_request.update(merge_error: nil) @merge_request.update(merge_error: nil)
if params[:merge_when_build_succeeds].present? if params[:merge_when_build_succeeds].present?
......
...@@ -7,6 +7,7 @@ module MergeRequests ...@@ -7,6 +7,7 @@ module MergeRequests
class PostMergeService < MergeRequests::BaseService class PostMergeService < MergeRequests::BaseService
def execute(merge_request) def execute(merge_request)
close_issues(merge_request) close_issues(merge_request)
todo_service.merge_merge_request(merge_request, current_user)
merge_request.mark_as_merged merge_request.mark_as_merged
create_merge_event(merge_request, current_user) create_merge_event(merge_request, current_user)
create_note(merge_request) create_note(merge_request)
......
...@@ -38,6 +38,30 @@ describe MergeRequests::MergeService, services: true do ...@@ -38,6 +38,30 @@ describe MergeRequests::MergeService, services: true do
end end
end end
context 'closes related todos' do
let(:merge_request) { create(:merge_request, assignee: user, author: user) }
let(:project) { merge_request.project }
let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') }
let!(:todo) do
create(:todo, :assigned,
project: project,
author: user,
user: user,
target: merge_request)
end
before do
allow(service).to receive(:execute_hooks)
perform_enqueued_jobs do
service.execute(merge_request)
todo.reload
end
end
it { expect(todo).to be_done }
end
context 'remove source branch by author' do context 'remove source branch by author' do
let(:service) do let(:service) do
merge_request.merge_params['force_remove_source_branch'] = '1' merge_request.merge_params['force_remove_source_branch'] = '1'
......
...@@ -79,8 +79,8 @@ describe MergeRequests::RefreshService, services: true do ...@@ -79,8 +79,8 @@ describe MergeRequests::RefreshService, services: true do
it { expect(@merge_request).to be_merged } it { expect(@merge_request).to be_merged }
it { expect(@fork_merge_request).to be_merged } it { expect(@fork_merge_request).to be_merged }
it { expect(@fork_merge_request.notes.last.note).to include('changed to merged') } it { expect(@fork_merge_request.notes.last.note).to include('changed to merged') }
it { expect(@build_failed_todo).to be_pending } it { expect(@build_failed_todo).to be_done }
it { expect(@fork_build_failed_todo).to be_pending } it { expect(@fork_build_failed_todo).to be_done }
end end
context 'manual merge of source branch' do context 'manual merge of source branch' do
...@@ -99,8 +99,8 @@ describe MergeRequests::RefreshService, services: true do ...@@ -99,8 +99,8 @@ describe MergeRequests::RefreshService, services: true do
it { expect(@merge_request.diffs.size).to be > 0 } it { expect(@merge_request.diffs.size).to be > 0 }
it { expect(@fork_merge_request).to be_merged } it { expect(@fork_merge_request).to be_merged }
it { expect(@fork_merge_request.notes.last.note).to include('changed to merged') } it { expect(@fork_merge_request.notes.last.note).to include('changed to merged') }
it { expect(@build_failed_todo).to be_pending } it { expect(@build_failed_todo).to be_done }
it { expect(@fork_build_failed_todo).to be_pending } it { expect(@fork_build_failed_todo).to be_done }
end end
context 'push to fork repo source branch' do context 'push to fork repo source branch' do
...@@ -149,8 +149,8 @@ describe MergeRequests::RefreshService, services: true do ...@@ -149,8 +149,8 @@ describe MergeRequests::RefreshService, services: true do
it { expect(@merge_request).to be_merged } it { expect(@merge_request).to be_merged }
it { expect(@fork_merge_request).to be_open } it { expect(@fork_merge_request).to be_open }
it { expect(@fork_merge_request.notes).to be_empty } it { expect(@fork_merge_request.notes).to be_empty }
it { expect(@build_failed_todo).to be_pending } it { expect(@build_failed_todo).to be_done }
it { expect(@fork_build_failed_todo).to be_pending } it { expect(@fork_build_failed_todo).to be_done }
end end
context 'push new branch that exists in a merge request' do context 'push new branch that exists in a merge request' do
......
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