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

Merge branch 'chatops-no-output' into 'master'

Handle empty chat output better

See merge request gitlab-org/gitlab-ee!4933
parents d64d1566 11663a5b
...@@ -59,7 +59,18 @@ module Gitlab ...@@ -59,7 +59,18 @@ module Gitlab
# #
# output - A `String` containing the output of a trace section. # output - A `String` containing the output of a trace section.
def without_executed_command_line(output) def without_executed_command_line(output)
output.split("\n")[1..-1].join("\n") # If `output.split("\n")` produces an empty Array then the slicing that
# follows it will produce a nil. For example:
#
# "\n".split("\n") # => []
# "\n".split("\n")[1..-1] # => nil
#
# To work around this we only "join" if we're given an Array.
if (converted = output.split("\n")[1..-1])
converted.join("\n")
else
''
end
end end
# Returns the trace section for the given name, or `nil` if the section # Returns the trace section for the given name, or `nil` if the section
......
...@@ -71,6 +71,14 @@ describe Gitlab::Chat::Output do ...@@ -71,6 +71,14 @@ describe Gitlab::Chat::Output do
expect(output.without_executed_command_line("hello\nworld")) expect(output.without_executed_command_line("hello\nworld"))
.to eq('world') .to eq('world')
end end
it 'returns an empty String when the input is empty' do
expect(output.without_executed_command_line('')).to eq('')
end
it 'returns an empty String when the input consits of a single newline' do
expect(output.without_executed_command_line("\n")).to eq('')
end
end end
describe '#find_build_trace_section' do describe '#find_build_trace_section' 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