BigW Consortium Gitlab

Commit f57cfdb6 by Grzegorz Bizon

Update order of build transition callbacks

parent ebeee311
...@@ -69,27 +69,28 @@ class CommitStatus < ActiveRecord::Base ...@@ -69,27 +69,28 @@ class CommitStatus < ActiveRecord::Base
commit_status.update_attributes finished_at: Time.now commit_status.update_attributes finished_at: Time.now
end end
after_transition [:created, :pending, :running] => :success do |commit_status|
MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status)
end
after_transition any => :failed do |commit_status|
MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status)
end
after_transition do |commit_status, transition| after_transition do |commit_status, transition|
return if transition.loopback? commit_status.pipeline.tap do |pipeline|
return if transition.loopback?
return unless pipeline
commit_status.pipeline.try(:id).try do |pipeline_id|
if commit_status.complete? if commit_status.complete?
ProcessPipelineWorker.perform_async(pipeline_id) ProcessPipelineWorker.perform_async(pipeline.id)
end end
UpdatePipelineWorker.perform_async(pipeline_id) UpdatePipelineWorker.perform_async(pipeline.id)
end end
true true
end end
after_transition [:created, :pending, :running] => :success do |commit_status|
MergeRequests::MergeWhenBuildSucceedsService.new(commit_status.pipeline.project, nil).trigger(commit_status)
end
after_transition any => :failed do |commit_status|
MergeRequests::AddTodoWhenBuildFailsService.new(commit_status.pipeline.project, nil).execute(commit_status)
end
end end
delegate :sha, :short_sha, to: :pipeline delegate :sha, :short_sha, to: :pipeline
......
...@@ -19,12 +19,11 @@ module MergeRequests ...@@ -19,12 +19,11 @@ module MergeRequests
end end
# Triggers the automatic merge of merge_request once the build succeeds # Triggers the automatic merge of merge_request once the build succeeds
def trigger(pipeline) def trigger(commit_status)
return unless pipeline.success? each_merge_request(commit_status) do |merge_request, pipeline|
each_merge_request(pipeline) do |merge_request|
next unless merge_request.merge_when_build_succeeds? next unless merge_request.merge_when_build_succeeds?
next unless merge_request.mergeable? next unless merge_request.mergeable?
next unless pipeline.success?
MergeWorker.perform_async(merge_request.id, merge_request.merge_user_id, merge_request.merge_params) MergeWorker.perform_async(merge_request.id, merge_request.merge_user_id, merge_request.merge_params)
end end
......
...@@ -4,9 +4,8 @@ class ProcessPipelineWorker ...@@ -4,9 +4,8 @@ class ProcessPipelineWorker
sidekiq_options queue: :default sidekiq_options queue: :default
def perform(pipeline_id) def perform(pipeline_id)
pipeline = Ci::Pipeline.find_by(id: pipeline_id) Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
return unless pipeline pipeline.process!
end
pipeline.process!
end end
end end
...@@ -4,9 +4,8 @@ class UpdatePipelineWorker ...@@ -4,9 +4,8 @@ class UpdatePipelineWorker
sidekiq_options queue: :default sidekiq_options queue: :default
def perform(pipeline_id) def perform(pipeline_id)
pipeline = Ci::Pipeline.find_by(id: pipeline_id) Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
return unless pipeline pipeline.update_status
end
pipeline.update_status
end end
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