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

45 lines
1012 B
Ruby
Raw Normal View History

2016-05-09 23:26:13 +00:00
module Ci
class CreatePipelineService < BaseService
def execute
unless ref_names.include?(params[:ref])
raise ArgumentError, 'Reference not found'
end
unless commit
raise ArgumentError, 'Commit not found'
end
unless can?(current_user, :create_pipeline, project)
raise RuntimeError, 'Insufficient permissions to create a new pipeline'
end
2016-05-15 00:47:16 +00:00
pipeline = new_pipeline
2016-05-09 23:26:13 +00:00
Ci::Commit.transaction do
unless pipeline.config_processor
raise ArgumentError, pipeline.yaml_errors || 'Missing .gitlab-ci.yml file'
end
pipeline.save!
pipeline.create_builds(current_user)
end
pipeline
end
private
2016-05-15 00:47:16 +00:00
def new_pipeline
project.ci_commits.new(sha: commit.id, ref: params[:ref], before_sha: Gitlab::Git::BLANK_SHA)
end
2016-05-09 23:26:13 +00:00
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