...
 
Commits (6)
...@@ -131,6 +131,26 @@ module QuickActions ...@@ -131,6 +131,26 @@ module QuickActions
end end
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 desc do
if issuable.allows_multiple_assignees? if issuable.allows_multiple_assignees?
'Remove all or specific assignee(s)' 'Remove all or specific assignee(s)'
...@@ -578,12 +598,12 @@ module QuickActions ...@@ -578,12 +598,12 @@ module QuickActions
users = extract_references(params, :user) users = extract_references(params, :user)
if users.empty? if users.empty?
users = users = case params
if params == 'me' when 'me'
[current_user] [current_user]
else else
User.where(username: params.split(' ').map(&:strip)) User.where(username: params.split(' ').map(&:strip))
end end
end end
users users
...@@ -606,6 +626,11 @@ module QuickActions ...@@ -606,6 +626,11 @@ module QuickActions
find_labels(labels_param).map(&:id) find_labels(labels_param).map(&:id)
end 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) def explain_commands(commands)
commands.map do |name, arg| commands.map do |name, arg|
definition = self.class.definition_by_name(name) 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. ...@@ -17,6 +17,7 @@ do.
| `/merge` | Merge (when pipeline succeeds) | | `/merge` | Merge (when pipeline succeeds) |
| `/title <New title>` | Change title | | `/title <New title>` | Change title |
| `/assign @username` | Assign | | `/assign @username` | Assign |
| `/pong` | Assign to previous assignee |
| `/unassign` | Remove assignee | | `/unassign` | Remove assignee |
| `/milestone %milestone` | Set milestone | | `/milestone %milestone` | Set milestone |
| `/remove_milestone` | Remove milestone | | `/remove_milestone` | Remove milestone |
...@@ -42,4 +43,4 @@ do. ...@@ -42,4 +43,4 @@ do.
| `/tableflip` | Append the comment with `(╯°□°)╯︵ ┻━┻` | | `/tableflip` | Append the comment with `(╯°□°)╯︵ ┻━┻` |
| `/shrug` | Append the comment with `¯\_(ツ)_/¯` | | `/shrug` | Append the comment with `¯\_(ツ)_/¯` |
| <code>/copy_metadata #issue &#124; !merge_request</code> | Copy labels and milestone from other issue or merge request | | <code>/copy_metadata #issue &#124; !merge_request</code> | Copy labels and milestone from other issue or merge request |
| `/confidential` | Makes the issue confidential | | `/confidential` | Makes the issue confidential |
\ No newline at end of file
...@@ -505,6 +505,26 @@ describe QuickActions::InterpretService do ...@@ -505,6 +505,26 @@ describe QuickActions::InterpretService do
end 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 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 it_behaves_like 'empty command' do
let(:content) { '/assign @abcd1234' } let(:content) { '/assign @abcd1234' }
let(:issuable) { issue } let(:issuable) { issue }
......