Commit a927bf56 authored by Arthur Gautier's avatar Arthur Gautier

Call merge request web hook for each commits

Call merge request web hook every times a new commit hits the
source branch
Signed-off-by: default avatarArthur Gautier <baloo@gandi.net>
parent 8b9e3af8
...@@ -55,6 +55,7 @@ v 7.11.0 (unreleased) ...@@ -55,6 +55,7 @@ v 7.11.0 (unreleased)
- Add "Create Merge Request" buttons to commits and branches pages and push event. - Add "Create Merge Request" buttons to commits and branches pages and push event.
- Show user roles by comments. - Show user roles by comments.
- Fix automatic blocking of auto-created users from Active Directory. - Fix automatic blocking of auto-created users from Active Directory.
- Call merge request web hook for each new commits (Arthur Gautier)
v 7.10.2 v 7.10.2
- Fix CI links on MR page - Fix CI links on MR page
......
...@@ -10,6 +10,7 @@ module MergeRequests ...@@ -10,6 +10,7 @@ module MergeRequests
close_merge_requests close_merge_requests
reload_merge_requests reload_merge_requests
execute_mr_web_hooks
comment_mr_with_commits comment_mr_with_commits
true true
...@@ -88,6 +89,20 @@ module MergeRequests ...@@ -88,6 +89,20 @@ module MergeRequests
end end
end end
# Call merge request webhook with update branches
def execute_mr_web_hooks
merge_requests = @project.origin_merge_requests.opened
.where(source_branch: @branch_name)
.to_a
merge_requests += @fork_merge_requests.where(source_branch: @branch_name)
.to_a
merge_requests = filter_merge_requests(merge_requests)
merge_requests.each do |merge_request|
execute_hooks(merge_request, 'update')
end
end
def filter_merge_requests(merge_requests) def filter_merge_requests(merge_requests)
merge_requests.uniq.select(&:source_project) merge_requests.uniq.select(&:source_project)
end end
......
...@@ -143,7 +143,7 @@ X-Gitlab-Event: Issue Hook ...@@ -143,7 +143,7 @@ X-Gitlab-Event: Issue Hook
## Merge request events ## Merge request events
Triggered when a new merge request is created or an existing merge request was updated/merged/closed. Triggered when a new merge request is created, an existing merge request was updated/merged/closed or a commit is added in the source branch.
**Request header**: **Request header**:
......
...@@ -30,11 +30,18 @@ describe MergeRequests::RefreshService do ...@@ -30,11 +30,18 @@ describe MergeRequests::RefreshService do
end end
context 'push to origin repo source branch' do context 'push to origin repo source branch' do
let(:refresh_service) { service.new(@project, @user) }
before do before do
service.new(@project, @user).execute(@oldrev, @newrev, 'refs/heads/master') allow(refresh_service).to receive(:execute_hooks)
refresh_service.execute(@oldrev, @newrev, 'refs/heads/master')
reload_mrs reload_mrs
end end
it 'should execute hooks with update action' do
expect(refresh_service).to have_received(:execute_hooks).
with(@merge_request, 'update')
end
it { expect(@merge_request.notes).not_to be_empty } it { expect(@merge_request.notes).not_to be_empty }
it { expect(@merge_request).to be_open } it { expect(@merge_request).to be_open }
it { expect(@fork_merge_request).to be_open } it { expect(@fork_merge_request).to be_open }
...@@ -54,11 +61,18 @@ describe MergeRequests::RefreshService do ...@@ -54,11 +61,18 @@ describe MergeRequests::RefreshService do
end end
context 'push to fork repo source branch' do context 'push to fork repo source branch' do
let(:refresh_service) { service.new(@fork_project, @user) }
before do before do
service.new(@fork_project, @user).execute(@oldrev, @newrev, 'refs/heads/master') allow(refresh_service).to receive(:execute_hooks)
refresh_service.execute(@oldrev, @newrev, 'refs/heads/master')
reload_mrs reload_mrs
end end
it 'should execute hooks with update action' do
expect(refresh_service).to have_received(:execute_hooks).
with(@fork_merge_request, 'update')
end
it { expect(@merge_request.notes).to be_empty } it { expect(@merge_request.notes).to be_empty }
it { expect(@merge_request).to be_open } it { expect(@merge_request).to be_open }
it { expect(@fork_merge_request.notes.last.note).to include('Added 4 commits') } it { expect(@fork_merge_request.notes.last.note).to include('Added 4 commits') }
......
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