summaryrefslogtreecommitdiff
path: root/app/services/ci
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2017-12-06 09:01:31 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2017-12-06 09:01:31 +0000
commit67a94b2ff3b0d714549c7d30b3c6212f3046a3c2 (patch)
tree9d99b4db7f5cbfbcb8e6143ac79d18403437ab45 /app/services/ci
parentf92292815868a67db53059cbe8e7607cc4891f47 (diff)
parentb328cff308431fd28a779f9356c9a43351de2754 (diff)
downloadgitlab-ce-67a94b2ff3b0d714549c7d30b3c6212f3046a3c2.tar.gz
Merge branch '37354-pipelines-update' into 'master'
Make sure head pippeline always corresponds with an MR Closes #37354 See merge request gitlab-org/gitlab-ce!14358
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/create_pipeline_service.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index 7b9ea223d26..1e5f2ed4dd2 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -29,7 +29,7 @@ module Ci
.new(pipeline, command, SEQUENCE)
sequence.build! do |pipeline, sequence|
- update_merge_requests_head_pipeline if pipeline.persisted?
+ schedule_head_pipeline_update
if sequence.complete?
cancel_pending_pipelines if project.auto_cancel_pending_pipelines?
@@ -38,15 +38,18 @@ module Ci
pipeline.process!
end
end
+
+ pipeline
end
private
- def update_merge_requests_head_pipeline
- return unless pipeline.latest?
+ def commit
+ @commit ||= project.commit(origin_sha || origin_ref)
+ end
- MergeRequest.where(source_project: @pipeline.project, source_branch: @pipeline.ref)
- .update_all(head_pipeline_id: @pipeline.id)
+ def sha
+ commit.try(:id)
end
def cancel_pending_pipelines
@@ -69,5 +72,15 @@ module Ci
@pipeline_created_counter ||= Gitlab::Metrics
.counter(:pipelines_created_total, "Counter of pipelines created")
end
+
+ def schedule_head_pipeline_update
+ related_merge_requests.each do |merge_request|
+ UpdateHeadPipelineForMergeRequestWorker.perform_async(merge_request.id)
+ end
+ end
+
+ def related_merge_requests
+ MergeRequest.where(source_project: pipeline.project, source_branch: pipeline.ref)
+ end
end
end