Commit f033ea19 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'refactor-pipeline-errors_message' into 'master'

Refactor pipeline.errors_message

Closes #12115

See merge request gitlab-org/gitlab-ee!14405
parents a8b0bc16 4c073161
......@@ -790,6 +790,10 @@ module Ci
stages.find_by!(name: name)
end
def error_messages
errors ? errors.full_messages.to_sentence : ""
end
private
def ci_yaml_from_repo
......
......@@ -65,7 +65,7 @@ module Ci
def execute!(*args, &block)
execute(*args, &block).tap do |pipeline|
unless pipeline.persisted?
raise CreateError, pipeline.errors.full_messages.join(',')
raise CreateError, pipeline.error_messages
end
end
end
......
......@@ -33,7 +33,7 @@ module MergeTrains
source_sha: merge_status[:source_id])
.execute(:merge_request_event, merge_request: merge_request)
return error(pipeline.errors.full_messages.join(',')) unless pipeline.persisted?
return error(pipeline.error_messages) unless pipeline.persisted?
success(pipeline: pipeline)
end
......
......@@ -2998,4 +2998,28 @@ describe Ci::Pipeline, :mailer do
end
end
end
describe '#error_messages' do
subject { pipeline.error_messages }
before do
pipeline.valid?
end
context 'when pipeline has errors' do
let(:pipeline) { build(:ci_pipeline, sha: nil, ref: nil) }
it 'returns the full error messages' do
is_expected.to eq("Sha can't be blank and Ref can't be blank")
end
end
context 'when pipeline does not have errors' do
let(:pipeline) { build(:ci_pipeline) }
it 'returns empty string' do
is_expected.to be_empty
end
end
end
end
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