Commit 94b3d33d authored by Lin Jen-Shin's avatar Lin Jen-Shin

If we use Rails magic it's breaking this test:

spec/lib/gitlab/data_builder/pipeline_data_builder_spec.rb

Because it would trigger the event just after saved and it would load
no builds and cache it. We should really avoid adding more magic.
parent 3f7680a6
...@@ -18,7 +18,6 @@ module Ci ...@@ -18,7 +18,6 @@ module Ci
# Invalidate object and save if when touched # Invalidate object and save if when touched
after_touch :update_state after_touch :update_state
after_save :execute_hooks_if_status_changed
after_save :keep_around_commits after_save :keep_around_commits
# ref can't be HEAD or SHA, can only be branch/tag name # ref can't be HEAD or SHA, can only be branch/tag name
...@@ -230,6 +229,7 @@ module Ci ...@@ -230,6 +229,7 @@ module Ci
def update_state def update_state
statuses.reload statuses.reload
last_status = status
self.status = if yaml_errors.blank? self.status = if yaml_errors.blank?
statuses.latest.status || 'skipped' statuses.latest.status || 'skipped'
else else
...@@ -238,11 +238,9 @@ module Ci ...@@ -238,11 +238,9 @@ module Ci
self.started_at = statuses.started_at self.started_at = statuses.started_at
self.finished_at = statuses.finished_at self.finished_at = statuses.finished_at
self.duration = statuses.latest.duration self.duration = statuses.latest.duration
save saved = save
end execute_hooks if last_status != status && saved && !skip_ci?
saved
def execute_hooks_if_status_changed
execute_hooks if status_changed? && !skip_ci?
end end
def execute_hooks def execute_hooks
......
...@@ -551,7 +551,7 @@ describe Ci::Pipeline, models: true do ...@@ -551,7 +551,7 @@ describe Ci::Pipeline, models: true do
before do before do
WebMock.stub_request(:post, hook.url) WebMock.stub_request(:post, hook.url)
pipeline.save pipeline.touch
ProjectWebHookWorker.drain ProjectWebHookWorker.drain
end end
......
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