BigW Consortium Gitlab

Commit cf292a3f by Grzegorz Bizon

Improve code clarity in pipeline create service

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