diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-04-30 16:27:56 +0700 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-05-21 17:58:47 +0700 |
commit | 81e4e3faa52ed5d8f70d0d1c6a031b33531674d5 (patch) | |
tree | 33b4e69a4ee3ebecaf14c10ff05951674db22943 | |
parent | 5396b2a81aba6ed2bf85906a3256e171337b6df0 (diff) | |
download | gitlab-ce-process-merge-trains-ce.tar.gz |
Process Merge Trainsprocess-merge-trains-ce
In order to process merge trains, we have central procedures
in MergeTrain model.
-rw-r--r-- | app/models/merge_request.rb | 4 | ||||
-rw-r--r-- | app/services/merge_requests/base_service.rb | 4 | ||||
-rw-r--r-- | app/services/merge_requests/create_pipeline_service.rb | 16 |
3 files changed, 22 insertions, 2 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index df162e4844c..0cfa4a17cf4 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -118,6 +118,10 @@ class MergeRequest < ApplicationRecord end end + after_transition any => [:merged, :closed] do |merge_request| + merge_request.run_after_commit { MergeTrain.process_async(merge_request) } + end + state :opened state :closed state :merged diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index bb9062e9b40..13500ba84ff 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -77,11 +77,11 @@ module MergeRequests end end - def can_create_pipeline_for?(merge_request) + def can_create_pipeline_for?(merge_request, allow_duplicate: false) ## # UpdateMergeRequestsWorker could be retried by an exception. # pipelines for merge request should not be recreated in such case. - return false if merge_request.find_actual_head_pipeline&.triggered_by_merge_request? + return false if !allow_duplicate && merge_request.find_actual_head_pipeline&.triggered_by_merge_request? return false if merge_request.has_no_commits? true diff --git a/app/services/merge_requests/create_pipeline_service.rb b/app/services/merge_requests/create_pipeline_service.rb new file mode 100644 index 00000000000..05bc524a871 --- /dev/null +++ b/app/services/merge_requests/create_pipeline_service.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module MergeRequests + class CreatePipelineService < MergeRequests::BaseService + extend ::Gitlab::Utils::Override + + def execute(merge_request) + create_pipeline_for(merge_request, current_user) + end + + override :can_create_pipeline_for? + def can_create_pipeline_for?(merge_request) + super(merge_request, allow_duplicate: true) + end + end +end |