...
 
Commits (6)
......@@ -131,6 +131,26 @@ module QuickActions
end
end
desc do
"Assigns to previous assignee"
end
explanation do
"Assigns 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)'
......@@ -578,8 +598,8 @@ module QuickActions
users = extract_references(params, :user)
if users.empty?
users =
if params == 'me'
users = case params
when 'me'
[current_user]
else
User.where(username: params.split(' ').map(&:strip))
......@@ -606,6 +626,11 @@ module QuickActions
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 explain_commands(commands)
commands.map do |name, arg|
definition = self.class.definition_by_name(name)
......
---
title: Added quick action "/pong" to allow quick return of issues and merge requests to an
approver or previous assignee.
merge_request:
author: E. Levi Allen
type: added
......@@ -17,6 +17,7 @@ do.
| `/merge` | Merge (when pipeline succeeds) |
| `/title <New title>` | Change title |
| `/assign @username` | Assign |
| `/pong` | Assign to previous assignee |
| `/unassign` | Remove assignee |
| `/milestone %milestone` | Set milestone |
| `/remove_milestone` | Remove milestone |
......
......@@ -505,6 +505,26 @@ describe QuickActions::InterpretService do
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 previous assignee 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 }
......