Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-18 21:02:10 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-18 21:02:10 +0300
commitef60b8e1685a8761477e822b3190a3a0cf4b0cfa (patch)
treebb81f3b0af997244ce01a6ee403b677686ad7a35 /app/services/ci/create_pipeline_service.rb
parent379dc6fbccc84858a392226111a0abadb54f0c04 (diff)
Use pipelines.errors when communicating the error
Diffstat (limited to 'app/services/ci/create_pipeline_service.rb')
-rw-r--r--app/services/ci/create_pipeline_service.rb36
1 files changed, 22 insertions, 14 deletions
diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb
index e13f4fce13d..b864807ec35 100644
--- a/app/services/ci/create_pipeline_service.rb
+++ b/app/services/ci/create_pipeline_service.rb
@@ -1,27 +1,39 @@
module Ci
class CreatePipelineService < BaseService
def execute
+ pipeline = project.ci_commits.new
+
unless ref_names.include?(params[:ref])
- raise ArgumentError, 'Reference not found'
+ pipeline.errors.add(:base, 'Reference not found')
+ return pipeline
end
unless commit
- raise ArgumentError, 'Commit not found'
+ pipeline.errors.add(:base, 'Commit not found')
+ return pipeline
end
unless can?(current_user, :create_pipeline, project)
- raise RuntimeError, 'Insufficient permissions to create a new pipeline'
+ pipeline.errors.add(:base, 'Insufficient permissions to create a new pipeline')
+ return pipeline
end
- pipeline = new_pipeline
+ begin
+ Ci::Commit.transaction do
+ pipeline.sha = commit.id
+ pipeline.ref = params[:ref]
+ pipeline.before_sha = Gitlab::Git::BLANK_SHA
- Ci::Commit.transaction do
- unless pipeline.config_processor
- raise ArgumentError, pipeline.yaml_errors || 'Missing .gitlab-ci.yml file'
- end
+ 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)
+ pipeline.save!
+ pipeline.create_builds(current_user)
+ end
+ rescue
+ pipeline.errors.add(:base, 'The pipeline could not be created. Please try again.')
end
pipeline
@@ -29,10 +41,6 @@ module Ci
private
- def new_pipeline
- project.ci_commits.new(sha: commit.id, ref: params[:ref], before_sha: Gitlab::Git::BLANK_SHA)
- end
-
def ref_names
@ref_names ||= project.repository.ref_names
end