Commit 5ad9d94d authored by Mehdi Lahmam's avatar Mehdi Lahmam

Add `/assign me` alias support for assigning issuables to oneself

Currently, when a user wants to assign an issue/MR to himself, he needs
to type his full username or select it from the suggested ones in the
dropdown list.
This commits suggest a faster solution which is typing `/assign me`

Closes #35304.
parent 4b3011e1
...@@ -511,7 +511,12 @@ module QuickActions ...@@ -511,7 +511,12 @@ module QuickActions
users = extract_references(params, :user) users = extract_references(params, :user)
if users.empty? if users.empty?
users = User.where(username: params.split(' ').map(&:strip)) users =
if params == 'me'
[current_user]
else
User.where(username: params.split(' ').map(&:strip))
end
end end
users users
......
...@@ -424,6 +424,26 @@ describe QuickActions::InterpretService do ...@@ -424,6 +424,26 @@ describe QuickActions::InterpretService do
end end
end end
context 'assign command with me alias' do
let(:content) { "/assign me" }
context 'Issue' do
it 'fetches assignee and populates assignee_ids if content contains /assign' do
_, updates = service.execute(content, issue)
expect(updates).to eq(assignee_ids: [developer.id])
end
end
context 'Merge Request' do
it 'fetches assignee and populates assignee_ids if content contains /assign' do
_, updates = service.execute(content, merge_request)
expect(updates).to eq(assignee_ids: [developer.id])
end
end
end
it_behaves_like 'empty command' do it_behaves_like 'empty command' do
let(:content) { '/assign @abcd1234' } let(:content) { '/assign @abcd1234' }
let(:issuable) { issue } let(:issuable) { issue }
......
...@@ -279,6 +279,17 @@ shared_examples 'issuable record that supports quick actions in its description ...@@ -279,6 +279,17 @@ shared_examples 'issuable record that supports quick actions in its description
expect(issuable.subscribed?(master, project)).to be_falsy expect(issuable.subscribed?(master, project)).to be_falsy
end end
end end
context "with a note assigning the #{issuable_type} to the current user" do
it "assigns the #{issuable_type} to the current user" do
write_note("/assign me")
expect(page).not_to have_content '/assign me'
expect(page).to have_content 'Commands applied'
expect(issuable.reload.assignees).to eq [master]
end
end
end end
describe "preview of note on #{issuable_type}" do describe "preview of note on #{issuable_type}" do
......
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