Commit 5b598ac9 authored by Markus Koller's avatar Markus Koller

Merge branch '241244-add-reviewers-quick-action-4' into 'master'

Add `/reassign_reviewer` command

See merge request gitlab-org/gitlab!47606
parents c1f34d8a c39e8be6
......@@ -62,6 +62,7 @@ The following quick actions are applicable to descriptions, discussions and thre
| `/publish` | ✓ | | | Publish issue to an associated [Status Page](../../operations/incident_management/status_page.md) ([Introduced in GitLab 13.0](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/30906)) **(ULTIMATE)** |
| `/reassign @user1 @user2` | ✓ | ✓ | | Replace current assignees with those specified. **(STARTER)** |
| `/rebase` | | ✓ | | Rebase source branch. This will schedule a background task that attempt to rebase the changes in the source branch on the latest commit of the target branch. If `/rebase` is used, `/merge` will be ignored to avoid a race condition where the source branch is merged or deleted before it is rebased. |
| `/reassign_reviewer @user1 @user2` | | ✓ | | Replace current reviewers with those specified. **(STARTER)** |
| `/relabel ~label1 ~label2` | ✓ | ✓ | ✓ | Replace current labels with those specified. |
| `/relate #issue1 #issue2` | ✓ | | | Mark issues as related. **(STARTER)** |
| `/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)** |
......
......@@ -11,6 +11,7 @@ module EE
include EE::Gitlab::QuickActions::EpicActions
include EE::Gitlab::QuickActions::IssueActions
include EE::Gitlab::QuickActions::IssueAndMergeRequestActions
include EE::Gitlab::QuickActions::MergeRequestActions
# rubocop: enable Cop/InjectEnterpriseEditionModule
end
end
......
---
title: Add `/reassign_reviewer` command
merge_request: 47606
author:
type: added
# frozen_string_literal: true
module EE
module Gitlab
module QuickActions
module MergeRequestActions
extend ActiveSupport::Concern
include ::Gitlab::QuickActions::Dsl
included do
desc _('Change reviewer(s)')
explanation _('Change reviewer(s).')
execution_message _('Changed reviewer(s).')
params '@user1 @user2'
types MergeRequest
condition do
quick_action_target.allows_multiple_reviewers? &&
::Feature.enabled?(:merge_request_reviewers, project, default_enabled: :yaml) &&
quick_action_target.persisted? &&
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", project)
end
command :reassign_reviewer do |reassign_param|
@updates[:reviewer_ids] = extract_users(reassign_param).map(&:id)
end
end
end
end
end
end
......@@ -4,11 +4,12 @@ require 'spec_helper'
RSpec.describe Notes::CreateService do
context 'note with commands' do
let(:project) { create(:project) }
let(:note_params) { opts }
context 'for issues' do
let(:project) { create(:project) }
let(:issuable) { create(:issue, project: project, weight: 10) }
let(:opts) { { noteable_type: 'Issue', noteable_id: issuable.id } }
let(:note_params) { opts }
it_behaves_like 'issuable quick actions' do
let(:quick_actions) do
......@@ -33,5 +34,30 @@ RSpec.describe Notes::CreateService do
end
end
end
context 'for merge_requests' do
let(:issuable) { create(:merge_request, project: project, source_project: project) }
let(:developer) { create(:user) }
let(:user) { create(:user) }
let(:opts) { { noteable_type: 'MergeRequest', noteable_id: issuable.id } }
it_behaves_like 'issuable quick actions' do
let(:quick_actions) do
[
QuickAction.new(
before_action: -> {
project.add_developer(developer)
issuable.update!(reviewers: [user])
},
action_text: "/reassign_reviewer #{developer.to_reference}",
expectation: ->(issuable, can_use_quick_action) {
expect(issuable.reviewers == [developer]).to eq(can_use_quick_action)
}
)
]
end
end
end
end
end
......@@ -16,6 +16,7 @@ RSpec.describe QuickActions::InterpretService do
before do
stub_licensed_features(multiple_issue_assignees: true,
multiple_merge_request_reviewers: true,
multiple_merge_request_assignees: true)
project.add_developer(current_user)
......@@ -272,6 +273,43 @@ RSpec.describe QuickActions::InterpretService do
end
end
context 'reassign_reviewer command' do
let(:content) { "/reassign_reviewer @#{current_user.username}" }
context "if the 'merge_request_reviewers' feature flag is on" do
context 'unlicensed' do
before do
stub_licensed_features(multiple_merge_request_reviewers: false)
end
it 'does not recognize /reassign_reviewer @user' do
content = "/reassign_reviewer @#{current_user.username}"
_, updates = service.execute(content, merge_request)
expect(updates).to be_empty
end
end
it 'reassigns reviewer if content contains /reassign_reviewer @user' do
_, updates = service.execute("/reassign_reviewer @#{current_user.username}", merge_request)
expect(updates[:reviewer_ids]).to match_array([current_user.id])
end
end
context "if the 'merge_request_reviewers' feature flag is off" do
before do
stub_feature_flags(merge_request_reviewers: false)
end
it 'does not recognize /reassign_reviewer @user' do
_, updates = service.execute(content, merge_request)
expect(updates).to be_empty
end
end
end
context 'iteration command' do
let_it_be(:iteration) { create(:iteration, group: group) }
......
......@@ -5218,6 +5218,12 @@ msgstr ""
msgid "Change permissions"
msgstr ""
msgid "Change reviewer(s)"
msgstr ""
msgid "Change reviewer(s)."
msgstr ""
msgid "Change status"
msgstr ""
......@@ -5284,6 +5290,9 @@ msgstr ""
msgid "Changed assignee(s)."
msgstr ""
msgid "Changed reviewer(s)."
msgstr ""
msgid "Changed the title to \"%{title_param}\"."
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