summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-04 12:25:06 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-10-04 14:43:58 +0200
commitf57cfdb6b527fe20f64f8a76339264948c3b358b (patch)
treea75b36b023086ca07c83a280abaa810dbc38647e
parentebeee31100cb142dfc74ec02928d3c5433eab8d7 (diff)
downloadgitlab-ce-f57cfdb6b527fe20f64f8a76339264948c3b358b.tar.gz
Update order of build transition callbacks
-rw-r--r--app/models/commit_status.rb25
-rw-r--r--app/services/merge_requests/merge_when_build_succeeds_service.rb7
-rw-r--r--app/workers/process_pipeline_worker.rb7
-rw-r--r--app/workers/update_pipeline_worker.rb7
4 files changed, 22 insertions, 24 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 09aec6b40d0..9c4f86144d8 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -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|
- 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?
- 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
diff --git a/app/services/merge_requests/merge_when_build_succeeds_service.rb b/app/services/merge_requests/merge_when_build_succeeds_service.rb
index 60d6085f9eb..4ad5fb08311 100644
--- a/app/services/merge_requests/merge_when_build_succeeds_service.rb
+++ b/app/services/merge_requests/merge_when_build_succeeds_service.rb
@@ -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
diff --git a/app/workers/process_pipeline_worker.rb b/app/workers/process_pipeline_worker.rb
index 9aad8cf818f..189cfa207ff 100644
--- a/app/workers/process_pipeline_worker.rb
+++ b/app/workers/process_pipeline_worker.rb
@@ -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
-
- pipeline.process!
+ Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
+ pipeline.process!
+ end
end
end
diff --git a/app/workers/update_pipeline_worker.rb b/app/workers/update_pipeline_worker.rb
index 31d29d0ab1c..9fd622a0970 100644
--- a/app/workers/update_pipeline_worker.rb
+++ b/app/workers/update_pipeline_worker.rb
@@ -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
-
- pipeline.update_status
+ Ci::Pipeline.find_by(id: pipeline_id).try do |pipeline|
+ pipeline.update_status
+ end
end
end