Commit a9dc6d28 authored by Valery Sizov's avatar Valery Sizov

Fix: /assignee should add assignees to MR and replace in an issue

parent 18444153
......@@ -92,9 +92,19 @@ module SlashCommands
desc 'Assign'
explanation do |users|
if issuable.is_a?(Issue)
"Assigns #{users.map(&:to_reference).to_sentence}." if users.any?
else
"Assigns #{users.last.to_reference}." if users.any?
end
end
params do
if issuable.is_a?(Issue)
['@user1 @user2']
else
['@user']
end
end
params '@user'
condition do
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end
......@@ -105,7 +115,8 @@ module SlashCommands
next if users.empty?
if issuable.is_a?(Issue)
@updates[:assignee_ids] = users.map(&:id)
# EE specific. In CE we should replace one assignee with another
@updates[:assignee_ids] = issuable.assignees.pluck(:id) + users.map(&:id)
else
@updates[:assignee_id] = users.last.id
end
......
......@@ -376,15 +376,21 @@ describe SlashCommands::InterpretService, services: true do
let(:content) { "/assign @#{developer.username}" }
context 'Issue' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
it 'fetches assignees and populates them if content contains /assign' do
user = create(:user)
issue.assignees << user
_, updates = service.execute(content, issue)
expect(updates).to eq(assignee_ids: [developer.id])
expect(updates[:assignee_ids]).to match_array([developer.id, user.id])
end
end
context 'Merge Request' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
user = create(:user)
merge_request.update(assignee: user)
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_id: developer.id)
......
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