Commit 26d9d312 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Resolve merge conflicts

parent 59e1353a
......@@ -2,7 +2,8 @@ module Ci
class CreatePipelineService < BaseService
attr_reader :pipeline
def execute(ignore_skip_ci: false, save_on_errors: true, trigger_request: nil)
def execute(ignore_skip_ci: false, save_on_errors: true, trigger_request: nil, mirror_update: false)
@pipeline = Ci::Pipeline.new(
project: project,
ref: ref,
......@@ -17,6 +18,10 @@ module Ci
return error('Pipeline is disabled')
end
unless project.mirror_trigger_builds?
return error('Pipeline is disabled for mirror updates') if mirror_update
end
unless trigger_request || can?(current_user, :create_pipeline, project)
return error('Insufficient permissions to create a new pipeline')
end
......
class CreateCommitBuildsService
def execute(project, user, params, mirror_update: false)
return unless project.builds_enabled?
return false if !project.mirror_trigger_builds? && mirror_update
before_sha = params[:checkout_sha] || params[:before]
sha = params[:checkout_sha] || params[:after]
origin_ref = params[:ref]
ref = Gitlab::Git.ref_name(origin_ref)
tag = Gitlab::Git.tag_ref?(origin_ref)
# Skip branch removal
if sha == Gitlab::Git::BLANK_SHA
return false
end
@pipeline = Ci::Pipeline.new(
project: project,
sha: sha,
ref: ref,
before_sha: before_sha,
tag: tag,
user: user)
##
# Skip creating pipeline if no gitlab-ci.yml is found
#
unless @pipeline.ci_yaml_file
return false
end
##
# Skip creating builds for commits that have [ci skip]
# but save pipeline object
#
if @pipeline.skip_ci?
return save_pipeline!
end
##
# Skip creating builds when CI config is invalid
# but save pipeline object
#
unless @pipeline.config_processor
return save_pipeline!
end
##
# Skip creating pipeline object if there are no builds for it.
#
unless @pipeline.create_builds(user)
@pipeline.errors.add(:base, 'No builds created')
return false
end
save_pipeline!
end
private
##
# Create a new pipeline and touch object to calculate status
#
def save_pipeline!
@pipeline.save!
@pipeline.touch
@pipeline
end
end
......@@ -74,12 +74,7 @@ class GitPushService < BaseService
SystemHooksService.new.execute_hooks(build_push_data_system_hook.dup, :push_hooks)
@project.execute_hooks(build_push_data.dup, :push_hooks)
@project.execute_services(build_push_data.dup, :push_hooks)
<<<<<<< HEAD
CreateCommitBuildsService.new.execute(@project, current_user, build_push_data, mirror_update: mirror_update)
=======
Ci::CreatePipelineService.new(project, current_user, build_push_data).execute
>>>>>>> 5a33bc984abfb4ee6243c00bbcc71ccd086d2266
Ci::CreatePipelineService.new(project, current_user, build_push_data).execute(mirror_update: mirror_update)
ProjectCacheWorker.perform_async(@project.id)
end
......
......@@ -11,16 +11,7 @@ class GitTagPushService < BaseService
SystemHooksService.new.execute_hooks(build_system_push_data.dup, :tag_push_hooks)
project.execute_hooks(@push_data.dup, :tag_push_hooks)
project.execute_services(@push_data.dup, :tag_push_hooks)
<<<<<<< HEAD
CreateCommitBuildsService.new.execute(
project,
current_user,
@push_data,
mirror_update: params[:mirror_update]
)
=======
Ci::CreatePipelineService.new(project, current_user, @push_data).execute
>>>>>>> 5a33bc984abfb4ee6243c00bbcc71ccd086d2266
Ci::CreatePipelineService.new(project, current_user, @push_data).execute(mirror_update: params[:mirror_update])
ProjectCacheWorker.perform_async(project.id)
true
......
......@@ -139,16 +139,8 @@ describe Ci::Pipeline, models: true do
end
end
<<<<<<< HEAD
describe '#update_state' do
it 'executes update_state after touching object' do
expect(pipeline).to receive(:update_state).and_return(true)
pipeline.touch
end
=======
describe '#reload_status!' do
let(:pipeline) { create :ci_empty_pipeline, project: project }
>>>>>>> 5a33bc984abfb4ee6243c00bbcc71ccd086d2266
context 'dependent objects' do
let(:commit_status) { create :commit_status, :pending, pipeline: pipeline }
......@@ -156,15 +148,9 @@ describe Ci::Pipeline, models: true do
it 'executes reload_status! after succeeding dependent object' do
expect(pipeline).to receive(:reload_status!).and_return(true)
<<<<<<< HEAD
it 'executes update_state after saving dependent object' do
expect(pipeline).to receive(:update_state).and_return(true)
commit_status.save
=======
commit_status.success
>>>>>>> 5a33bc984abfb4ee6243c00bbcc71ccd086d2266
end
end
ends
context 'updates' do
let(:current) { Time.now.change(usec: 0) }
......
......@@ -14,14 +14,7 @@ describe Ci::API::API do
end
describe "POST /builds/register" do
<<<<<<< HEAD
it "starts a build" do
pipeline = FactoryGirl.create(:ci_pipeline, project: project, ref: 'master')
pipeline.create_builds(nil)
build = pipeline.builds.first
=======
let!(:build) { create(:ci_build, pipeline: pipeline, name: 'spinach', stage: 'test', stage_idx: 0) }
>>>>>>> 5a33bc984abfb4ee6243c00bbcc71ccd086d2266
it "starts a build" do
register_builds info: { platform: :darwin }
......@@ -37,22 +30,10 @@ describe Ci::API::API do
)
end
<<<<<<< HEAD
it "returns 404 error if no pending build found" do
post ci_api("/builds/register"), token: runner.token
expect(response).to have_http_status(404)
end
it "returns 404 error if no builds for specific runner" do
pipeline = FactoryGirl.create(:ci_pipeline, project: shared_project)
FactoryGirl.create(:ci_build, pipeline: pipeline, status: 'pending')
=======
context 'when builds are finished' do
before do
build.success
end
>>>>>>> 5a33bc984abfb4ee6243c00bbcc71ccd086d2266
it "returns 404 error if no builds for specific runner" do
register_builds
......@@ -61,17 +42,11 @@ describe Ci::API::API do
end
end
<<<<<<< HEAD
it "returns 404 error if no builds for shared runner" do
pipeline = FactoryGirl.create(:ci_pipeline, project: project)
FactoryGirl.create(:ci_build, pipeline: pipeline, status: 'pending')
=======
context 'for other project with builds' do
before do
build.success
create(:ci_build, :pending)
end
>>>>>>> 5a33bc984abfb4ee6243c00bbcc71ccd086d2266
it "returns 404 error if no builds for shared runner" do
register_builds
......
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