diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index defa579f9a8..751aae2696d 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -643,7 +643,7 @@ module QuickActions if users.empty? users = - if params == 'me' + if params.strip == 'me' [current_user] else User.where(username: params.split(' ').map(&:strip)) diff --git a/changelogs/unreleased/52772-assign-me-quick-action-doesn-t-work-if-there-is-extra-white-space.yml b/changelogs/unreleased/52772-assign-me-quick-action-doesn-t-work-if-there-is-extra-white-space.yml new file mode 100644 index 00000000000..4451cdd78b5 --- /dev/null +++ b/changelogs/unreleased/52772-assign-me-quick-action-doesn-t-work-if-there-is-extra-white-space.yml @@ -0,0 +1,5 @@ +--- +title: Resolve assign-me quick action doesn't work if there is extra white space +merge_request: 22402 +author: +type: fixed diff --git a/doc/user/project/quick_actions.md b/doc/user/project/quick_actions.md index c2f53540089..0a4542b71ed 100644 --- a/doc/user/project/quick_actions.md +++ b/doc/user/project/quick_actions.md @@ -24,6 +24,7 @@ discussions, and descriptions: | `/reopen` | Reopen | ✓ | ✓ | | `/title ` | Change title | ✓ | ✓ | | `/award :emoji:` | Toggle emoji award | ✓ | ✓ | +| `/assign me` | Assign yourself | ✓ | ✓ | | `/assign @user` | Assign one user | ✓ | ✓ | | `/assign @user1 @user2` | Assign multiple users **[STARTER]** | ✓ | | | `/unassign` | Remove assignee(s) | ✓ | ✓ | diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index ac0ca1f33a5..41a170e4f25 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -380,6 +380,14 @@ describe QuickActions::InterpretService do end end + shared_examples 'assign command' do + it 'assigns to a single user' do + _, updates = service.execute(content, issuable) + + expect(updates).to eq(assignee_ids: [developer.id]) + end + end + it_behaves_like 'reopen command' do let(:content) { '/reopen' } let(:issuable) { issue } @@ -474,67 +482,56 @@ describe QuickActions::InterpretService do let(:issuable) { issue } end - context 'assign command' do - let(:content) { "/assign @#{developer.username}" } - - context 'Issue' do - it 'fetches assignee and populates assignee_ids if content contains /assign' do - _, updates = service.execute(content, issue) - - expect(updates[:assignee_ids]).to match_array([developer.id]) - end + context 'assign command with one user' do + it_behaves_like 'assign command' do + let(:content) { "/assign @#{developer.username}" } + let(:issuable) { issue } 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 + it_behaves_like 'assign command' do + let(:content) { "/assign @#{developer.username}" } + let(:issuable) { merge_request } end end + # CE does not have multiple assignees context 'assign command with multiple assignees' do - let(:content) { "/assign @#{developer.username} @#{developer2.username}" } - before do project.add_developer(developer2) end - context 'Issue' do - it 'fetches assignee and populates assignee_ids if content contains /assign' do - _, updates = service.execute(content, issue) - - expect(updates[:assignee_ids]).to match_array([developer.id]) - end + it_behaves_like 'assign command' do + let(:content) { "/assign @#{developer.username} @#{developer2.username}" } + let(:issuable) { issue } 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 + it_behaves_like 'assign command' do + let(:content) { "/assign @#{developer.username} @#{developer2.username}" } + let(:issuable) { merge_request } 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 + it_behaves_like 'assign command' do + let(:content) { '/assign me' } + let(:issuable) { issue } end - context 'Merge Request' do - it 'fetches assignee and populates assignee_ids if content contains /assign' do - _, updates = service.execute(content, merge_request) + it_behaves_like 'assign command' do + let(:content) { '/assign me' } + let(:issuable) { merge_request } + end + end - expect(updates).to eq(assignee_ids: [developer.id]) - end + context 'assign command with me alias and whitespace' do + it_behaves_like 'assign command' do + let(:content) { '/assign me ' } + let(:issuable) { issue } + end + + it_behaves_like 'assign command' do + let(:content) { '/assign me ' } + let(:issuable) { merge_request } end end