gitlab-org--gitlab-foss/app/services/ci/create_pipeline_service.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

2016-05-09 23:26:13 +00:00
module Ci
class CreatePipelineService < BaseService
def execute
pipeline = project.pipelines.new(params)
2016-05-09 23:26:13 +00:00
unless ref_names.include?(params[:ref])
pipeline.errors.add(:base, 'Reference not found')
return pipeline
2016-05-09 23:26:13 +00:00
end
if commit
pipeline.sha = commit.id
else
pipeline.errors.add(:base, 'Commit not found')
return pipeline
2016-05-09 23:26:13 +00:00
end
unless can?(current_user, :create_pipeline, project)
pipeline.errors.add(:base, 'Insufficient permissions to create a new pipeline')
return pipeline
2016-05-09 23:26:13 +00:00
end
unless pipeline.config_processor
pipeline.errors.add(:base, pipeline.yaml_errors || 'Missing .gitlab-ci.yml file')
return pipeline
end
2016-05-15 00:47:16 +00:00
pipeline.save!
2016-05-09 23:26:13 +00:00
unless pipeline.create_builds(current_user)
pipeline.errors.add(:base, 'No builds for this pipeline.')
2016-05-09 23:26:13 +00:00
end
pipeline.save
2016-05-09 23:26:13 +00:00
pipeline
end
private
def ref_names
@ref_names ||= project.repository.ref_names
end
def commit
@commit ||= project.commit(params[:ref])
end
end
2016-05-12 18:08:18 +00:00
end