summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-06-20 15:03:25 +0200
committerToon Claes <toon@gitlab.com>2017-06-20 15:03:25 +0200
commitfcd46c1af4ceeec7813a91111dfce5e492695119 (patch)
treed2d927e483c395339e8830bc2fa858b43538b665
parent132cd0092d6aea87359a9a0627ad2c53c4a91837 (diff)
downloadgitlab-ce-fcd46c1af4ceeec7813a91111dfce5e492695119.tar.gz
Backport /reassign quick command
The /reassign quick command works even when no multiple assignees are allowed of there isn't any assignee yet. So for consistency, it's also be backported to CE. But it functions the same as the /assign quick action.
-rw-r--r--app/services/quick_actions/interpret_service.rb18
-rw-r--r--spec/services/quick_actions/interpret_service_spec.rb18
2 files changed, 35 insertions, 1 deletions
diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb
index 8adfd939c2e..4ceabaf021e 100644
--- a/app/services/quick_actions/interpret_service.rb
+++ b/app/services/quick_actions/interpret_service.rb
@@ -150,6 +150,24 @@ module QuickActions
end
end
+ desc do
+ "Change assignee#{'(s)' if issuable.allows_multiple_assignees?}"
+ end
+ explanation do |users|
+ users = issuable.allows_multiple_assignees? ? users : users.take(1)
+ "Change #{'assignee'.pluralize(users.size)} to #{users.map(&:to_reference).to_sentence}."
+ end
+ params do
+ issuable.allows_multiple_assignees? ? '@user1 @user2' : '@user'
+ end
+ condition do
+ issuable.persisted? &&
+ current_user.can?(:"admin_#{issuable.to_ability_name}", project)
+ end
+ command :reassign do |unassign_param|
+ @updates[:assignee_ids] = extract_users(unassign_param).map(&:id)
+ end
+
desc 'Set milestone'
explanation do |milestone|
"Sets the milestone to #{milestone.to_reference}." if milestone
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb
index c9e63efbc14..b1997e64557 100644
--- a/spec/services/quick_actions/interpret_service_spec.rb
+++ b/spec/services/quick_actions/interpret_service_spec.rb
@@ -362,7 +362,7 @@ describe QuickActions::InterpretService, services: true do
it 'fetches assignee and populates assignee_id if content contains /assign' do
_, updates = service.execute(content, issue)
- expect(updates).to eq(assignee_ids: [developer.id])
+ expect(updates[:assignee_ids]).to match_array([developer.id])
end
end
@@ -431,6 +431,22 @@ describe QuickActions::InterpretService, services: true do
end
end
+ context 'reassign command' do
+ let(:content) { '/reassign' }
+
+ context 'Issue' do
+ it 'reassigns user if content contains /reassign @user' do
+ user = create(:user)
+
+ issue.update(assignee_ids: [developer.id])
+
+ _, updates = service.execute("/reassign @#{user.username}", issue)
+
+ expect(updates).to eq(assignee_ids: [user.id])
+ end
+ end
+ end
+
it_behaves_like 'milestone command' do
let(:content) { "/milestone %#{milestone.title}" }
let(:issuable) { issue }