Commit 855bceb3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'submit_review_quick_action_2' into 'master'

Add quick action for submitting a review

See merge request gitlab-org/gitlab!22061
parents 79c33b31 651ff7df
......@@ -4,9 +4,7 @@ module Notes
class CreateService < ::Notes::BaseService
# rubocop:disable Metrics/CyclomaticComplexity
def execute
merge_request_diff_head_sha = params.delete(:merge_request_diff_head_sha)
note = Notes::BuildService.new(project, current_user, params).execute
note = Notes::BuildService.new(project, current_user, params.except(:merge_request_diff_head_sha)).execute
# n+1: https://gitlab.com/gitlab-org/gitlab-foss/issues/37440
note_valid = Gitlab::GitalyClient.allow_n_plus_1_calls do
......@@ -23,8 +21,7 @@ module Notes
quick_actions_service = QuickActionsService.new(project, current_user)
if quick_actions_service.supported?(note)
options = { merge_request_diff_head_sha: merge_request_diff_head_sha }
content, update_params, message = quick_actions_service.execute(note, options)
content, update_params, message = quick_actions_service.execute(note, quick_action_options)
only_commands = content.empty?
......@@ -74,6 +71,11 @@ module Notes
private
# EE::Notes::CreateService would override this method
def quick_action_options
{ merge_request_diff_head_sha: params[:merge_request_diff_head_sha] }
end
def tracking_data_for(note)
label = Gitlab.ee? && note.author == User.visual_review_bot ? 'anonymous_visual_review_note' : 'note'
......@@ -84,3 +86,5 @@ module Notes
end
end
end
Notes::CreateService.prepend_if_ee('EE::Notes::CreateService')
......@@ -352,7 +352,10 @@ bottom of the screen with two buttons:
Clicking **Submit review** will publish all comments. Any quick actions
submitted are performed at this time.
Alternatively, every pending comment has a button to finish the entire review.
Alternatively, to finish the entire review from a pending comment:
- Click the **Finish review** button on the comment.
- Use the `/submit_review` [quick action](../project/quick_actions.md) in the text of non-review comment.
![Review submission](img/review_preview.png)
......
......@@ -68,7 +68,8 @@ The following quick actions are applicable to descriptions, discussions and thre
| `/remove_zoom` | ✓ | | | Remove Zoom meeting from this issue. ([Introduced in GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/merge_requests/16609)) |
| `/target_branch <local branch name>` | | ✓ | | Set target branch |
| `/wip` | | ✓ | | Toggle the Work In Progress status |
| `/approve` | | ✓ | | Approve the merge request |
| `/approve` | | ✓ | | Approve the merge request **(STARTER)** |
| `/submit_review` | | ✓ | | Submit a pending review. ([Introduced in GitLab 12.7](https://gitlab.com/gitlab-org/gitlab/issues/8041)) **(PREMIUM)** |
| `/merge` | | ✓ | | Merge (when pipeline succeeds) |
| `/child_epic <epic>` | | | ✓ | Add child epic to `<epic>`. The `<epic>` value should be in the format of `&epic`, `group&epic`, or a URL to an epic. ([Introduced in GitLab 12.0](https://gitlab.com/gitlab-org/gitlab/issues/7330)) **(ULTIMATE)** |
| `/remove_child_epic <epic>` | | | ✓ | Remove child epic from `<epic>`. The `<epic>` value should be in the format of `&epic`, `group&epic`, or a URL to an epic. ([Introduced in GitLab 12.0](https://gitlab.com/gitlab-org/gitlab/issues/7330)) **(ULTIMATE)** |
......
# frozen_string_literal: true
module EE
module Notes
module CreateService
extend ::Gitlab::Utils::Override
override :quick_action_options
def quick_action_options
super.merge(review_id: params[:review_id])
end
end
end
end
---
title: Added submit_review quick action
merge_request: 22061
author:
type: added
......@@ -20,6 +20,23 @@ module EE
@execution_message[:approve] = _('Approved the current merge request.')
end
end
desc _('Submit a review')
explanation _('Submit the current review.')
types MergeRequest
condition do
quick_action_target.persisted? && quick_action_target.project.feature_available?(:batch_comments, current_user)
end
command :submit_review do
next if params[:review_id]
result = DraftNotes::PublishService.new(quick_action_target, current_user).execute
@execution_message[:submit_review] = if result[:status] == :success
_('Submitted the current review.')
else
result[:message]
end
end
end
end
end
......
......@@ -708,6 +708,34 @@ describe QuickActions::InterpretService do
end
end
context 'submit_review command' do
using RSpec::Parameterized::TableSyntax
where(:note) do
[
'I like it',
'/submit_review'
]
end
with_them do
let(:merge_request) { create(:merge_request, source_project: project) }
let(:content) { '/submit_review' }
let!(:draft_note) { create(:draft_note, note: note, merge_request: merge_request, author: current_user) }
before do
stub_licensed_features(batch_comments: true)
end
it 'submits the users current review' do
_, _, message = service.execute(content, merge_request)
expect { draft_note.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(message).to eq('Submitted the current review.')
end
end
end
shared_examples 'weight command' do
it 'populates weight specified by the /weight command' do
_, updates = service.execute(content, issuable)
......
......@@ -17283,6 +17283,9 @@ msgstr ""
msgid "Subkeys"
msgstr ""
msgid "Submit a review"
msgstr ""
msgid "Submit as spam"
msgstr ""
......@@ -17298,6 +17301,12 @@ msgstr ""
msgid "Submit search"
msgstr ""
msgid "Submit the current review."
msgstr ""
msgid "Submitted the current review."
msgstr ""
msgid "Subscribe"
msgstr ""
......
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