Commit 94584d52 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg

Add approve quick action

When a MR can be merged, an approval might be missing which makes the
`/merge` quick action a bit weird as it doesn't execute. Through this
commit a `/approve` is added so the following will work:

```
/approve
/merge
```

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/1873
parent e65e6972
...@@ -51,6 +51,7 @@ discussions, and descriptions: ...@@ -51,6 +51,7 @@ discussions, and descriptions:
| `/move path/to/project` | Move this issue to another project | ✓ | | | `/move path/to/project` | Move this issue to another project | ✓ | |
| `/target_branch <Local branch Name>` | Set target branch | | ✓ | | `/target_branch <Local branch Name>` | Set target branch | | ✓ |
| `/wip` | Toggle the Work In Progress status | | ✓ | | `/wip` | Toggle the Work In Progress status | | ✓ |
| `/approve` | Approve the merge request | | ✓ |
| `/merge` | Merge (when pipeline succeeds) | | ✓ | | `/merge` | Merge (when pipeline succeeds) | | ✓ |
......
...@@ -72,6 +72,17 @@ module EE ...@@ -72,6 +72,17 @@ module EE
@updates[:epic] = nil @updates[:epic] = nil
end end
desc 'Approve a merge request'
explanation 'Approve the current merge request'
condition do
issuable.is_a?(MergeRequest) && issuable.persisted? && issuable.can_approve?(current_user)
end
command :approve do
if issuable.can_approve?(current_user)
::MergeRequests::ApprovalService.new(issuable.project, current_user).execute(issuable)
end
end
def extract_epic(params) def extract_epic(params)
return nil if params.nil? return nil if params.nil?
......
---
title: Add approve quick action
merge_request: 7989
author:
type: added
...@@ -177,6 +177,30 @@ describe QuickActions::InterpretService do ...@@ -177,6 +177,30 @@ describe QuickActions::InterpretService do
end end
end end
end end
context 'approve command' do
let(:merge_request) { create(:merge_request, source_project: project) }
let(:content) { '/approve' }
it 'approves the current merge request' do
service.execute(content, merge_request)
expect(merge_request.approved_by_users).to eq([current_user])
end
context "when the user can't approve" do
before do
project.team.truncate
project.add_guest(current_user)
end
it 'does not approve the MR' do
service.execute(content, merge_request)
expect(merge_request.approved_by_users).to be_empty
end
end
end
end end
describe '#explain' do describe '#explain' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment