Commit 2cf082ec authored by Valery Sizov's avatar Valery Sizov

[Issue multiple assignee] Support multips assignee in slash commands

parent e442812f
......@@ -86,15 +86,18 @@ module SlashCommands
current_user.can?(:"admin_#{issuable.to_ability_name}", project)
end
command :assign do |assignee_param|
user = extract_references(assignee_param, :user).first
user ||= User.find_by(username: assignee_param)
users = extract_references(assignee_param, :user)
next unless user
if users.empty?
users = User.find_by(username: assignee_param.split(' ').map(&:strip))
end
next if users.empty?
if issuable.is_a?(Issue)
@updates[:assignee_ids] = [user.id]
@updates[:assignee_ids] = users.map(&:id)
else
@updates[:assignee_id] = user.id
@updates[:assignee_id] = users.last.id
end
end
......
......@@ -3,6 +3,7 @@ require 'spec_helper'
describe SlashCommands::InterpretService, services: true do
let(:project) { create(:project, :public) }
let(:developer) { create(:user) }
let(:developer2) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:milestone) { create(:milestone, project: project, title: '9.10') }
let(:inprogress) { create(:label, project: project, title: 'In Progress') }
......@@ -388,6 +389,28 @@ describe SlashCommands::InterpretService, services: true do
end
end
context 'assign command with multiple assignees' do
let(:content) { "/assign @#{developer.username} @#{developer2.username}" }
before{ project.team << [developer2, :developer] }
context 'Issue' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
_, updates = service.execute(content, issue)
expect(updates[:assignee_ids]).to match_array([developer.id, developer2.id])
end
end
context 'Merge Request' do
it 'fetches assignee and populates assignee_id if content contains /assign' do
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_id: developer.id)
end
end
end
it_behaves_like 'empty command' do
let(:content) { '/assign @abcd1234' }
let(:issuable) { issue }
......
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