diff options
author | Arthur Gautier <baloo@gandi.net> | 2015-02-26 11:17:25 +0300 |
---|---|---|
committer | Arthur Gautier <baloo@gandi.net> | 2015-05-13 10:33:20 +0300 |
commit | a927bf56b16c10bafc5bd9a14d034d2898b45c8e (patch) | |
tree | 12decb137680ab1158b110d5f281c2e62939bacf | |
parent | 8b9e3af8bf7a6089a11ef3f5eb91dfef4940a3f4 (diff) |
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: Arthur Gautier <baloo@gandi.net>
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/services/merge_requests/refresh_service.rb | 15 | ||||
-rw-r--r-- | doc/web_hooks/web_hooks.md | 2 | ||||
-rw-r--r-- | spec/services/merge_requests/refresh_service_spec.rb | 18 |
4 files changed, 33 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG index d9c8d38991d..3d92a81a5ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -55,6 +55,7 @@ v 7.11.0 (unreleased) - Add "Create Merge Request" buttons to commits and branches pages and push event. - Show user roles by comments. - 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 - Fix CI links on MR page diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index 66610a08a44..d0648da049b 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -10,6 +10,7 @@ module MergeRequests close_merge_requests reload_merge_requests + execute_mr_web_hooks comment_mr_with_commits true @@ -88,6 +89,20 @@ module MergeRequests 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) merge_requests.uniq.select(&:source_project) end diff --git a/doc/web_hooks/web_hooks.md b/doc/web_hooks/web_hooks.md index 01082555192..d140f3a457a 100644 --- a/doc/web_hooks/web_hooks.md +++ b/doc/web_hooks/web_hooks.md @@ -143,7 +143,7 @@ X-Gitlab-Event: Issue Hook ## 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**: diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 879df0c9c67..0f9b65678df 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -30,11 +30,18 @@ describe MergeRequests::RefreshService do end context 'push to origin repo source branch' do + let(:refresh_service) { service.new(@project, @user) } 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 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).to be_open } it { expect(@fork_merge_request).to be_open } @@ -54,11 +61,18 @@ describe MergeRequests::RefreshService do end context 'push to fork repo source branch' do + let(:refresh_service) { service.new(@fork_project, @user) } 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 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).to be_open } it { expect(@fork_merge_request.notes.last.note).to include('Added 4 commits') } |