Commit 48389e99 authored by Shinya Maeda's avatar Shinya Maeda

Fix pipeline

parent 19789154
module Ci module Ci
class CreatePipelineService < BaseService class CreatePipelineService < BaseService
class ParameterValidationError < StandardError end class InsufficientConditionError < StandardError
attr_reader :pipeline
def initialize(pipeline)
@pipeline = pipeline
end
end
attr_reader :pipeline attr_reader :pipeline
...@@ -32,8 +38,8 @@ module Ci ...@@ -32,8 +38,8 @@ module Ci
.execute(pipeline) .execute(pipeline)
end end
rescue ParameterValidationError => e rescue InsufficientConditionError => e
return e return e.pipeline
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
return error("Failed to persist the pipeline: #{e}") return error("Failed to persist the pipeline: #{e}")
...@@ -53,39 +59,39 @@ module Ci ...@@ -53,39 +59,39 @@ module Ci
def validate(triggering_user, ignore_skip_ci:, save_on_errors:) def validate(triggering_user, ignore_skip_ci:, save_on_errors:)
unless project.builds_enabled? unless project.builds_enabled?
raise ParameterValidationError, error('Pipeline is disabled') raise InsufficientConditionError, error('Pipeline is disabled')
end end
unless allowed_to_trigger_pipeline?(triggering_user) unless allowed_to_trigger_pipeline?(triggering_user)
if can?(triggering_user, :create_pipeline, project) if can?(triggering_user, :create_pipeline, project)
raise ParameterValidationError, error("Insufficient permissions for protected ref '#{ref}'") raise InsufficientConditionError, error("Insufficient permissions for protected ref '#{ref}'")
else else
raise ParameterValidationError, error('Insufficient permissions to create a new pipeline') raise InsufficientConditionError, error('Insufficient permissions to create a new pipeline')
end end
end end
unless branch? || tag? unless branch? || tag?
raise ParameterValidationError, error('Reference not found') raise InsufficientConditionError, error('Reference not found')
end end
unless commit unless commit
raise ParameterValidationError, error('Commit not found') raise InsufficientConditionError, error('Commit not found')
end end
unless pipeline.config_processor unless pipeline.config_processor
unless pipeline.ci_yaml_file unless pipeline.ci_yaml_file
raise ParameterValidationError, error("Missing #{pipeline.ci_yaml_file_path} file") raise InsufficientConditionError, error("Missing #{pipeline.ci_yaml_file_path} file")
end end
raise ParameterValidationError, error(pipeline.yaml_errors, save: save_on_errors) raise InsufficientConditionError, error(pipeline.yaml_errors, save: save_on_errors)
end end
if !ignore_skip_ci && skip_ci? if !ignore_skip_ci && skip_ci?
pipeline.skip if save_on_errors pipeline.skip if save_on_errors
return pipeline raise InsufficientConditionError, pipeline
end end
unless pipeline.has_stage_seeds? unless pipeline.has_stage_seeds?
raise ParameterValidationError, error('No stages / jobs for this pipeline.') raise InsufficientConditionError, error('No stages / jobs for this pipeline.')
end end
end end
......
...@@ -40,15 +40,6 @@ describe Ci::PipelineTriggerService, services: true do ...@@ -40,15 +40,6 @@ describe Ci::PipelineTriggerService, services: true do
expect(result[:pipeline].variables.first.value).to eq(variables.values.first) expect(result[:pipeline].variables.first.value).to eq(variables.values.first)
end end
end end
context 'when params have two variables and keys are duplicated' do
let(:variables) { [{ key: 'AAA', value: 'AAA123' }, { key: 'AAA', value: 'BBB123' }] }
it 'returns error' do
expect { result }.not_to change { Ci::Pipeline.count }
expect(result[:http_status]).to eq(400)
end
end
end end
context 'when params have a non-existsed ref' do context 'when params have a non-existsed ref' do
......
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