Commit cf292a3f authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve code clarity in pipeline create service

parent e45fd5a1
...@@ -100,7 +100,7 @@ module Ci ...@@ -100,7 +100,7 @@ module Ci
def create_builds(user, trigger_request = nil) def create_builds(user, trigger_request = nil)
build_builds(user, 'success', trigger_request) build_builds(user, 'success', trigger_request)
save! save
end end
def create_next_builds(build) def create_next_builds(build)
......
...@@ -14,26 +14,50 @@ class CreateCommitBuildsService ...@@ -14,26 +14,50 @@ class CreateCommitBuildsService
return false return false
end end
pipeline = Ci::Pipeline.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag) @pipeline = Ci::Pipeline.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag)
# Skip creating pipeline when no gitlab-ci.yml is found ##
unless pipeline.ci_yaml_file # Skip creating pipeline if no gitlab-ci.yml is found
return pipeline #
unless @pipeline.ci_yaml_file
return false
end end
##
# Skip creating builds for commits that have [ci skip] # Skip creating builds for commits that have [ci skip]
if !pipeline.skip_ci? && pipeline.config_processor # but save pipeline object
# Create builds for commit #
unless pipeline.build_builds(user) if @pipeline.skip_ci?
pipeline.errors.add(:base, 'No builds created') return save_pipeline!
return pipeline end
##
# Skip creating builds when CI config is invalid
# but save pipeline object
#
unless @pipeline.config_processor
return save_pipeline!
end end
##
# Skip creating pipeline object if there are no builds for it.
#
unless @pipeline.build_builds(user)
@pipeline.errors.add(:base, 'No builds created')
return false
end
save_pipeline!
end end
# Create a new pipeline private
pipeline.save!
pipeline.touch ##
pipeline # Create a new pipeline and touch object to calculate status
#
def save_pipeline!
@pipeline.save!
@pipeline.touch
@pipeline
end end
end end
...@@ -60,7 +60,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -60,7 +60,7 @@ describe CreateCommitBuildsService, services: true do
after: '31das312', after: '31das312',
commits: [{ message: 'Message' }] commits: [{ message: 'Message' }]
) )
expect(result).not_to be_persisted expect(result).to be_falsey
expect(Ci::Pipeline.count).to eq(0) expect(Ci::Pipeline.count).to eq(0)
end end
...@@ -184,7 +184,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -184,7 +184,7 @@ describe CreateCommitBuildsService, services: true do
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: [{ message: 'some msg' }]) commits: [{ message: 'some msg' }])
expect(result).not_to be_persisted expect(result).to be_falsey
expect(Ci::Build.all).to be_empty expect(Ci::Build.all).to be_empty
expect(Ci::Pipeline.count).to eq(0) expect(Ci::Pipeline.count).to eq(0)
end end
......
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