Commit 9e06bde2 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Make sure we only fire hooks upon status changed

parent 3691a391
......@@ -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
......
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