diff options
author | Rémy Coutable <remy@rymai.me> | 2017-08-07 16:45:10 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-08-07 16:45:10 +0300 |
commit | cfcd1601522c52be96097956b0e3a56be3a3ffcb (patch) | |
tree | fb7d76383e80e0a257dfa20ac229a029e5c3799a | |
parent | c1a8cffe7e0769d28be3e03aba938069d29c8902 (diff) | |
parent | 74f8b5c3d0581cdc8a88171a08200d89895ed9df (diff) |
Merge branch 'add-assign-me-alias' into 'master'
Add `/assign me` alias support for assigning issuables to oneself
Closes #35304
See merge request !13334
4 files changed, 42 insertions, 6 deletions
diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index c22bf7498bb..c7832c47e1a 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -511,7 +511,12 @@ module QuickActions users = extract_references(params, :user) 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 users diff --git a/spec/features/merge_requests/user_uses_slash_commands_spec.rb b/spec/features/merge_requests/user_uses_slash_commands_spec.rb index 43cab65d287..95c50df1896 100644 --- a/spec/features/merge_requests/user_uses_slash_commands_spec.rb +++ b/spec/features/merge_requests/user_uses_slash_commands_spec.rb @@ -3,17 +3,17 @@ require 'rails_helper' feature 'Merge Requests > User uses quick actions', js: true do include QuickActionsHelpers - let(:user) { create(:user) } - let(:project) { create(:project, :public, :repository) } - let(:merge_request) { create(:merge_request, source_project: project) } - let!(:milestone) { create(:milestone, project: project, title: 'ASAP') } - it_behaves_like 'issuable record that supports quick actions in its description and notes', :merge_request do let(:issuable) { create(:merge_request, source_project: project) } let(:new_url_opts) { { merge_request: { source_branch: 'feature', target_branch: 'master' } } } end describe 'merge-request-only commands' do + let(:user) { create(:user) } + let(:project) { create(:project, :public, :repository) } + let(:merge_request) { create(:merge_request, source_project: project) } + let!(:milestone) { create(:milestone, project: project, title: 'ASAP') } + before do project.team << [user, :master] sign_in(user) diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index b78ecfb61c4..30fa0ee6873 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -424,6 +424,26 @@ describe QuickActions::InterpretService do 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 let(:content) { '/assign @abcd1234' } let(:issuable) { issue } diff --git a/spec/support/features/issuable_slash_commands_shared_examples.rb b/spec/support/features/issuable_slash_commands_shared_examples.rb index 32835e391a8..68f0ce8afb3 100644 --- a/spec/support/features/issuable_slash_commands_shared_examples.rb +++ b/spec/support/features/issuable_slash_commands_shared_examples.rb @@ -279,6 +279,17 @@ shared_examples 'issuable record that supports quick actions in its description expect(issuable.subscribed?(master, project)).to be_falsy 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 describe "preview of note on #{issuable_type}" do |