From 7d45aa88a2ef05136fb6e9130b9a0592e4770ec1 Mon Sep 17 00:00:00 2001 From: "E. Levi Allen" Date: Wed, 25 Jul 2018 08:05:57 -0400 Subject: [PATCH 1/3] Updating Tests --- .../quick_actions/interpret_service_spec.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 51629a048572a5..87c46c3040348d 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -547,6 +547,26 @@ end end end + + context 'pong command' do + let(:content) { "/pong" } + + context 'Issue' do + it 'fetches previous assignee and populates assignee_ids if content contains /pong' do + _, updates = service.execute(content, issue) + + expect(updates).not_to eq(assignee_ids: [developer.id]) + end + end + + context 'Merge Request' do + it 'fetches assigner and populates assignee_ids if content contains /pong' do + _, updates = service.execute(content, merge_request) + + expect(updates).not_to eq(assignee_ids: [developer.id]) + end + end + end it_behaves_like 'empty command' do let(:content) { '/assign @abcd1234' } -- GitLab From 9552ef0953dd8df511d8cc7967bd74b609c274e8 Mon Sep 17 00:00:00 2001 From: Levi Date: Wed, 25 Jul 2018 16:00:50 -0400 Subject: [PATCH 2/3] Merging CE-48640 to EE --- .../quick_actions/interpret_service.rb | 41 ++++++++++++++++--- changelogs/unreleased/gl-ce-48640.yml | 6 +++ doc/user/project/quick_actions.md | 9 ++++ .../quick_actions/interpret_service_spec.rb | 20 +++++++++ 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 changelogs/unreleased/gl-ce-48640.yml diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index 61762bffe0c05f..1d9ef9868b47a0 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -134,6 +134,26 @@ def extractor end end + desc do + "Returns to previous assignee" + end + explanation do + "Returns to previous assignee." + end + condition do + issuable.is_a?(MergeRequest) && + current_user.can?(:"admin_#{issuable.to_ability_name}", project) + end + parse_params do |pong_param| + extract_users(pong_param) + end + command :pong do + previous_assignee = find_previous_assignee(issuable) + next if previous_assignee == "" + + @updates[:assignee_ids] = [previous_assignee.author.id] + end + desc do if issuable.allows_multiple_assignees? 'Remove all or specific assignee(s)' @@ -581,12 +601,12 @@ def extract_users(params) users = extract_references(params, :user) if users.empty? - users = - if params == 'me' - [current_user] - else - User.where(username: params.split(' ').map(&:strip)) - end + users = case params + when 'me' + [current_user] + else + User.where(username: params.split(' ').map(&:strip)) + end end users @@ -609,6 +629,15 @@ def find_label_ids(labels_param) find_labels(labels_param).map(&:id) end + def find_previous_assignee(merge_request) + merge_request.notes.system.find_by("note like ? and author_id != ?", + "%assigned to @#{current_user.username}%", current_user.id) || "" + end + + def find_pong_recipient(project, params = {}) + log_info([project, params]) + end + def explain_commands(commands) commands.map do |name, arg| definition = self.class.definition_by_name(name) diff --git a/changelogs/unreleased/gl-ce-48640.yml b/changelogs/unreleased/gl-ce-48640.yml new file mode 100644 index 00000000000000..624a489a2b1ab3 --- /dev/null +++ b/changelogs/unreleased/gl-ce-48640.yml @@ -0,0 +1,6 @@ +--- +title: Added quick action"/pong" to allow quick return of issues and merge requests to an + approver or previous assignee. +merge_request: +author: +type: added diff --git a/doc/user/project/quick_actions.md b/doc/user/project/quick_actions.md index de60d36928ba17..375dc630c96d98 100644 --- a/doc/user/project/quick_actions.md +++ b/doc/user/project/quick_actions.md @@ -16,9 +16,15 @@ do. | `/reopen` | Reopen the issue or merge request | | `/merge` | Merge (when pipeline succeeds) | | `/title ` | Change title | +<<<<<<< ours | `/assign @user1 @user2 ` | Add assignee(s) | | `/reassign @user1 @user2 ` | Change assignee(s) | | `/unassign @user1 @user2` | Remove all or specific assignee(s) | +======= +| `/assign @username` | Assign | +| `/pong` | Return to previous assignee| +| `/unassign` | Remove assignee | +>>>>>>> theirs | `/milestone %milestone` | Set milestone | | `/remove_milestone` | Remove milestone | | `/label ~foo ~"bar baz"` | Add label(s) | @@ -46,6 +52,9 @@ do. | `/shrug` | Append the comment with `¯\_(ツ)_/¯` | | /copy_metadata #issue | !merge_request | Copy labels and milestone from other issue or merge request | | `/confidential` | Makes the issue confidential | +<<<<<<< ours Note: In GitLab Starter every issue can have more than one assignee, so commands `/assign`, `/unassign` and `/reassign` support multiple assignees. +======= +>>>>>>> theirs diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 87c46c3040348d..c7376a8f911651 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -568,6 +568,26 @@ end end + context 'pong command' do + let(:content) { "/pong" } + + context 'Issue' do + it 'fetches previous assignee and populates assignee_ids if content contains /pong' do + _, updates = service.execute(content, issue) + + expect(updates).not_to eq(assignee_ids: [developer.id]) + end + end + + context 'Merge Request' do + it 'fetches assigner and populates assignee_ids if content contains /pong' do + _, updates = service.execute(content, merge_request) + + expect(updates).not_to eq(assignee_ids: [developer.id]) + end + end + end + it_behaves_like 'empty command' do let(:content) { '/assign @abcd1234' } let(:issuable) { issue } -- GitLab From 5f2b8bbc537992245f7c9a2f413de90428c256ab Mon Sep 17 00:00:00 2001 From: Levi Date: Wed, 25 Jul 2018 17:13:14 -0400 Subject: [PATCH 3/3] Modifying whitespace --- spec/services/quick_actions/interpret_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index c7376a8f911651..dd59111f12dca6 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -547,7 +547,7 @@ end end end - + context 'pong command' do let(:content) { "/pong" } -- GitLab