Commit 5e7b7e85 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'approval-unapproval-webhooks' into 'master'

Approval  & Unapproval Webhooks

See merge request gitlab-org/gitlab-ee!8742
parents 0e8501a1 187a7c84
...@@ -14,6 +14,8 @@ module MergeRequests ...@@ -14,6 +14,8 @@ module MergeRequests
if merge_request.approvals_left.zero? if merge_request.approvals_left.zero?
notification_service.async.approve_mr(merge_request, current_user) notification_service.async.approve_mr(merge_request, current_user)
execute_hooks(merge_request, 'approved') execute_hooks(merge_request, 'approved')
else
execute_hooks(merge_request, 'approval')
end end
end end
end end
......
...@@ -13,12 +13,13 @@ module MergeRequests ...@@ -13,12 +13,13 @@ module MergeRequests
if approval.destroy_all # rubocop: disable DestroyAll if approval.destroy_all # rubocop: disable DestroyAll
merge_request.reset_approval_cache! merge_request.reset_approval_cache!
create_note(merge_request) create_note(merge_request)
if currently_approved if currently_approved
notification_service.async.unapprove_mr(merge_request, current_user) notification_service.async.unapprove_mr(merge_request, current_user)
execute_hooks(merge_request, 'unapproved') execute_hooks(merge_request, 'unapproved')
else
execute_hooks(merge_request, 'unapproval')
end end
end end
end end
......
---
title: Add approval and unapproval webhooks
merge_request: 8742
author:
type: added
...@@ -51,9 +51,9 @@ describe MergeRequests::ApprovalService do ...@@ -51,9 +51,9 @@ describe MergeRequests::ApprovalService do
end end
context 'with remaining approvals' do context 'with remaining approvals' do
it 'does not fire a webhook' do it 'fires an approval webhook' do
expect(merge_request).to receive(:approvals_left).and_return(5) expect(merge_request).to receive(:approvals_left).and_return(5)
expect(service).not_to receive(:execute_hooks) expect(service).to receive(:execute_hooks).with(merge_request, 'approval')
service.execute(merge_request) service.execute(merge_request)
end end
...@@ -75,7 +75,7 @@ describe MergeRequests::ApprovalService do ...@@ -75,7 +75,7 @@ describe MergeRequests::ApprovalService do
allow(service).to receive(:notification_service).and_return(notification_service) allow(service).to receive(:notification_service).and_return(notification_service)
end end
it 'fires a webhook' do it 'fires an approved webhook' do
expect(service).to receive(:execute_hooks).with(merge_request, 'approved') expect(service).to receive(:execute_hooks).with(merge_request, 'approved')
service.execute(merge_request) service.execute(merge_request)
......
...@@ -35,6 +35,12 @@ describe MergeRequests::RemoveApprovalService do ...@@ -35,6 +35,12 @@ describe MergeRequests::RemoveApprovalService do
execute! execute!
end end
it 'fires an unapproval webhook' do
expect(service).to receive(:execute_hooks).with(merge_request, 'unapproval')
execute!
end
it 'does not send a notification' do it 'does not send a notification' do
expect(service).not_to receive(:notification_service) expect(service).not_to receive(:notification_service)
...@@ -56,6 +62,12 @@ describe MergeRequests::RemoveApprovalService do ...@@ -56,6 +62,12 @@ describe MergeRequests::RemoveApprovalService do
allow(service).to receive(:notification_service).and_return(notification_service) allow(service).to receive(:notification_service).and_return(notification_service)
end end
it 'fires an unapproved webhook' do
expect(service).to receive(:execute_hooks).with(merge_request, 'unapproved')
execute!
end
it 'sends a notification' do it 'sends a notification' do
expect(notification_service).to receive_message_chain(:async, :unapprove_mr).with(merge_request, user) expect(notification_service).to receive_message_chain(:async, :unapprove_mr).with(merge_request, user)
......
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