summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2017-05-25 18:14:40 -0300
committerFelipe Artur <felipefac@gmail.com>2017-05-29 15:37:56 -0300
commitfe790c7543a3f3b618ca8b7238aeb73ff51cfde3 (patch)
tree24fa498c89026b17da723e98d74d7cb37fbb13c1 /app
parent5b9e801e819b6daf1804874ed962bc2f1650c8da (diff)
downloadgitlab-ce-fe790c7543a3f3b618ca8b7238aeb73ff51cfde3.tar.gz
Set head pipeline when creating merge requestsissue_32225_2
Diffstat (limited to 'app')
-rw-r--r--app/services/ci/create_pipeline_service.rb21
-rw-r--r--app/services/merge_requests/create_service.rb18
2 files changed, 28 insertions, 11 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index 801ff410fb5..a98b7167765 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -61,6 +61,16 @@ module Ci
private
+ def update_merge_requests_head_pipeline
+ merge_requests = MergeRequest.where(source_branch: @pipeline.ref, source_project: @pipeline.project)
+
+ merge_requests = merge_requests.select do |mr|
+ mr.diff_head_sha == @pipeline.sha
+ end
+
+ MergeRequest.where(id: merge_requests).update_all(head_pipeline_id: @pipeline.id)
+ end
+
def skip_ci?
return false unless pipeline.git_commit_message
pipeline.git_commit_message =~ /\[(ci[ _-]skip|skip[ _-]ci)\]/i
@@ -118,17 +128,6 @@ module Ci
origin_sha && origin_sha != Gitlab::Git::BLANK_SHA
end
- def update_merge_requests_head_pipeline
- merge_requests = MergeRequest.where(source_branch: @pipeline.ref, source_project: @pipeline.project)
-
- merge_requests_ids =
- merge_requests.select do |mr|
- mr.diff_head_sha == @pipeline.sha
- end.map(&:id)
-
- MergeRequest.where(id: merge_requests_ids).update_all(head_pipeline_id: @pipeline.id)
- end
-
def error(message, save: false)
pipeline.errors.add(:base, message)
pipeline.drop if save
diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb
index b0ae2dfe4ce..fbf171f705e 100644
--- a/app/services/merge_requests/create_service.rb
+++ b/app/services/merge_requests/create_service.rb
@@ -11,7 +11,9 @@ module MergeRequests
merge_request = MergeRequest.new
merge_request.source_project = source_project
+ merge_request.source_branch = params[:source_branch]
merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch)
+ merge_request.head_pipeline = head_pipeline_for(merge_request)
create(merge_request)
end
@@ -22,5 +24,21 @@ module MergeRequests
todo_service.new_merge_request(issuable, current_user)
issuable.cache_merge_request_closes_issues!(current_user)
end
+
+ private
+
+ def head_pipeline_for(merge_request)
+ return unless merge_request.source_project
+
+ sha = merge_request.source_branch_head&.id
+
+ return unless sha
+
+ pipelines =
+ Ci::Pipeline.where(ref: merge_request.source_branch, project_id: merge_request.source_project.id, sha: sha).
+ order(id: :desc)
+
+ pipelines.first
+ end
end
end