Commit b46b9d5e authored by Stan Hu's avatar Stan Hu

Fix pipelines not always being created after a push

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/31741 introduced
a regression where not all the right parameters would be passed into
`Ci::CreatePipelineService`. We fix this by breaking out the pipeline
parameters and reusing a method from `Gitlab::DataBuilder::Push`.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/66196
parent 1068483f
...@@ -56,7 +56,7 @@ module Git ...@@ -56,7 +56,7 @@ module Git
return unless params.fetch(:create_pipelines, true) return unless params.fetch(:create_pipelines, true)
Ci::CreatePipelineService Ci::CreatePipelineService
.new(project, current_user, base_params) .new(project, current_user, pipeline_params)
.execute(:push, pipeline_options) .execute(:push, pipeline_options)
end end
...@@ -75,24 +75,29 @@ module Git ...@@ -75,24 +75,29 @@ module Git
ProjectCacheWorker.perform_async(project.id, file_types, [], false) ProjectCacheWorker.perform_async(project.id, file_types, [], false)
end end
def base_params def pipeline_params
{ {
oldrev: params[:oldrev], before: params[:oldrev],
newrev: params[:newrev], after: params[:newrev],
ref: params[:ref], ref: params[:ref],
push_options: params[:push_options] || {} push_options: params[:push_options] || {},
checkout_sha: Gitlab::DataBuilder::Push.checkout_sha(
project.repository, params[:newrev], params[:ref])
} }
end end
def push_data_params(commits:, with_changed_files: true) def push_data_params(commits:, with_changed_files: true)
base_params.merge( {
oldrev: params[:oldrev],
newrev: params[:newrev],
ref: params[:ref],
project: project, project: project,
user: current_user, user: current_user,
commits: commits, commits: commits,
message: event_message, message: event_message,
commits_count: commits_count, commits_count: commits_count,
with_changed_files: with_changed_files with_changed_files: with_changed_files
) }
end end
def event_push_data def event_push_data
......
---
title: Fix pipelines not always being created after a push
merge_request: 31927
author:
type: fixed
...@@ -129,8 +129,6 @@ module Gitlab ...@@ -129,8 +129,6 @@ module Gitlab
SAMPLE_DATA SAMPLE_DATA
end end
private
def checkout_sha(repository, newrev, ref) def checkout_sha(repository, newrev, ref)
# Checkout sha is nil when we remove branch or tag # Checkout sha is nil when we remove branch or tag
return if Gitlab::Git.blank_ref?(newrev) return if Gitlab::Git.blank_ref?(newrev)
......
...@@ -76,6 +76,22 @@ describe Git::BranchPushService, services: true do ...@@ -76,6 +76,22 @@ describe Git::BranchPushService, services: true do
stub_ci_pipeline_to_return_yaml_file stub_ci_pipeline_to_return_yaml_file
end end
it 'creates a pipeline with the right parameters' do
expect(Ci::CreatePipelineService)
.to receive(:new)
.with(project,
user,
{
before: oldrev,
after: newrev,
ref: ref,
checkout_sha: SeedRepo::Commit::ID,
push_options: {}
}).and_call_original
subject
end
it "creates a new pipeline" do it "creates a new pipeline" do
expect { subject }.to change { Ci::Pipeline.count } expect { subject }.to change { Ci::Pipeline.count }
......
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