diff --git a/lib/gitlab/quick_actions/merge_request_actions.rb b/lib/gitlab/quick_actions/merge_request_actions.rb index c9aa047310a3c8ca135d3efa0ed2eb98cb0042d7..eeda543519d0a34bf4996d7711d77f91a22ea96d 100644 --- a/lib/gitlab/quick_actions/merge_request_actions.rb +++ b/lib/gitlab/quick_actions/merge_request_actions.rb @@ -254,11 +254,23 @@ module MergeRequestActions quick_action_target.persisted? && quick_action_target.eligible_for_approval_by?(current_user) && !quick_action_target.merged? end command :approve do + @execution_message[:approve] = [] + + if quick_action_target.draft_notes.authored_by(current_user).any? + result = DraftNotes::PublishService.new(quick_action_target, current_user).execute + + @execution_message[:approve] = if result[:status] == :success + [_('Submitted the current review.')] + else + [result[:message]] + end + end + success = ::MergeRequests::ApprovalService.new(project: quick_action_target.project, current_user: current_user).execute(quick_action_target) next unless success - @execution_message[:approve] = _('Approved the current merge request.') + @execution_message[:approve] << _('Approved the current merge request.') end ######################################################################## diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 5fbb5a064cfd29e4af56b9d18a87bee84ac78834..0607025b9d32380df7f6766a986c0ee37b873355 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -3299,6 +3299,25 @@ expect(merge_request.approved_by_users).to eq([developer]) end + context 'when user has review comments' do + it 'submits the users current review' do + draft_note = create(:draft_note, merge_request: merge_request, author: developer) + + _, _, message = service.execute(content, merge_request) + + expect { draft_note.reload }.to raise_error(ActiveRecord::RecordNotFound) + expect(merge_request.approved_by_users).to eq([developer]) + expect(message).to eq("Submitted the current review. Approved the current merge request.") + end + + it 'does not submit review if there is no draft notes' do + _, _, message = service.execute(content, merge_request) + + expect(merge_request.approved_by_users).to eq([developer]) + expect(message).to eq("Approved the current merge request.") + end + end + context "when the user can't approve" do before do project.team.truncate