diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-05-19 20:42:43 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-05-19 20:42:43 +0000 |
commit | bd0cecfdf6ec504421b44f1174040c5003c13f65 (patch) | |
tree | 200c89a047765c7578bc34c16065d8b2ee81980a /app/services | |
parent | 53e2d30af4f5a23d4f58c051293188e891c385fa (diff) | |
parent | 4f1c63683175fa88ca41ba2180b68e266d7118e4 (diff) | |
download | gitlab-ce-bd0cecfdf6ec504421b44f1174040c5003c13f65.tar.gz |
Merge branch 'with-pipeline-view' into 'master'
Add pipeline view
This is continuation of https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/3653
cc @DouweM @grzesiek
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/17551
Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/15625
See merge request !3703
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/ci/create_pipeline_service.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb new file mode 100644 index 00000000000..5bc0c31cb42 --- /dev/null +++ b/app/services/ci/create_pipeline_service.rb @@ -0,0 +1,50 @@ +module Ci + class CreatePipelineService < BaseService + def execute + pipeline = project.ci_commits.new(params) + + unless ref_names.include?(params[:ref]) + pipeline.errors.add(:base, 'Reference not found') + return pipeline + end + + unless commit + pipeline.errors.add(:base, 'Commit not found') + return pipeline + end + + unless can?(current_user, :create_pipeline, project) + pipeline.errors.add(:base, 'Insufficient permissions to create a new pipeline') + return pipeline + end + + begin + Ci::Commit.transaction do + pipeline.sha = commit.id + + unless pipeline.config_processor + pipeline.errors.add(:base, pipeline.yaml_errors || 'Missing .gitlab-ci.yml file') + raise ActiveRecord::Rollback + end + + pipeline.save! + pipeline.create_builds(current_user) + end + rescue + pipeline.errors.add(:base, 'The pipeline could not be created. Please try again.') + end + + pipeline + end + + private + + def ref_names + @ref_names ||= project.repository.ref_names + end + + def commit + @commit ||= project.commit(params[:ref]) + end + end +end |