Commit 7d3d46d2 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'zj-approval-slash-command' into 'master'

Add approve quick action

Closes #1873

See merge request gitlab-org/gitlab-ee!7989
parents da4d5ecf 94584d52
......@@ -51,6 +51,7 @@ discussions, and descriptions:
| `/move path/to/project` | Move this issue to another project | ✓ | |
| `/target_branch <Local branch Name>` | Set target branch | | ✓ |
| `/wip` | Toggle the Work In Progress status | | ✓ |
| `/approve` | Approve the merge request | | ✓ |
| `/merge` | Merge (when pipeline succeeds) | | ✓ |
......
......@@ -72,6 +72,17 @@ module EE
@updates[:epic] = nil
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)
return nil if params.nil?
......
---
title: Add approve quick action
merge_request: 7989
author:
type: added
......@@ -177,6 +177,30 @@ describe QuickActions::InterpretService do
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
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