Commit f57cfdb6 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Update order of build transition callbacks

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