Make sure we only fire hooks upon status changed
This commit is contained in:
parent
3691a39152
commit
9e06bde269
2 changed files with 24 additions and 4 deletions
|
@ -18,7 +18,7 @@ module Ci
|
|||
|
||||
# Invalidate object and save if when touched
|
||||
after_touch :update_state
|
||||
after_touch :execute_hooks_unless_ci_skipped
|
||||
after_save :execute_hooks_if_status_changed
|
||||
after_save :keep_around_commits
|
||||
|
||||
# ref can't be HEAD or SHA, can only be branch/tag name
|
||||
|
@ -241,8 +241,8 @@ module Ci
|
|||
save
|
||||
end
|
||||
|
||||
def execute_hooks_unless_ci_skipped
|
||||
execute_hooks unless skip_ci?
|
||||
def execute_hooks_if_status_changed
|
||||
execute_hooks if status_changed? && !skip_ci?
|
||||
end
|
||||
|
||||
def execute_hooks
|
||||
|
|
|
@ -551,7 +551,7 @@ describe Ci::Pipeline, models: true do
|
|||
|
||||
before do
|
||||
WebMock.stub_request(:post, hook.url)
|
||||
pipeline.touch
|
||||
pipeline.save
|
||||
ProjectWebHookWorker.drain
|
||||
end
|
||||
|
||||
|
@ -561,6 +561,26 @@ describe Ci::Pipeline, models: true do
|
|||
it 'executes pipeline_hook after touched' do
|
||||
expect(WebMock).to have_requested(:post, hook.url).once
|
||||
end
|
||||
|
||||
context 'with multiple builds' do
|
||||
def create_build(name)
|
||||
create(:ci_build, :pending, pipeline: pipeline, name: name)
|
||||
end
|
||||
|
||||
let(:build_a) { create_build('a') }
|
||||
let(:build_b) { create_build('b') }
|
||||
|
||||
before do
|
||||
build_a.run
|
||||
build_b.run
|
||||
build_a.success
|
||||
build_b.success
|
||||
end
|
||||
|
||||
it 'fires 3 hooks' do
|
||||
expect(WebMock).to have_requested(:post, hook.url).times(3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with pipeline hooks disabled' do
|
||||
|
|
Loading…
Reference in a new issue