From 570940858599fb2f4e5410b9a6743a0aeb0a09e7 Mon Sep 17 00:00:00 2001 From: Alessio Caiazza Date: Wed, 20 Sep 2017 16:03:53 +0200 Subject: Hide CI section markers from job trace --- changelogs/unreleased/37970-timestamped-ci.yml | 5 +++++ lib/gitlab/ci/ansi2html.rb | 13 ++++++++++++- spec/lib/gitlab/ci/ansi2html_spec.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/37970-timestamped-ci.yml diff --git a/changelogs/unreleased/37970-timestamped-ci.yml b/changelogs/unreleased/37970-timestamped-ci.yml new file mode 100644 index 00000000000..2a4797f069a --- /dev/null +++ b/changelogs/unreleased/37970-timestamped-ci.yml @@ -0,0 +1,5 @@ +--- +title: Strip gitlab-runner section markers in build trace HTML view +merge_request: 14393 +author: +type: added diff --git a/lib/gitlab/ci/ansi2html.rb b/lib/gitlab/ci/ansi2html.rb index ad78ae244b2..088adbdd267 100644 --- a/lib/gitlab/ci/ansi2html.rb +++ b/lib/gitlab/ci/ansi2html.rb @@ -155,7 +155,9 @@ module Gitlab stream.each_line do |line| s = StringScanner.new(line) until s.eos? - if s.scan(/\e([@-_])(.*?)([@-~])/) + if s.scan(/section_((?:start)|(?:end)):(\d+):([^\r]+)\r\033\[0K/) + handle_section(s) + elsif s.scan(/\e([@-_])(.*?)([@-~])/) handle_sequence(s) elsif s.scan(/\e(([@-_])(.*?)?)?$/) break @@ -183,6 +185,15 @@ module Gitlab ) end + def handle_section(s) + action = s[1] + timestamp = s[2] + section = s[3] + line = s.matched()[0...-5] # strips \r\033[0K + + @out << %{} + end + def handle_sequence(s) indicator = s[1] commands = s[2].split ';' diff --git a/spec/lib/gitlab/ci/ansi2html_spec.rb b/spec/lib/gitlab/ci/ansi2html_spec.rb index e6645985ba4..33540eab5d6 100644 --- a/spec/lib/gitlab/ci/ansi2html_spec.rb +++ b/spec/lib/gitlab/ci/ansi2html_spec.rb @@ -195,6 +195,32 @@ describe Gitlab::Ci::Ansi2html do end end + context "with section markers" do + let(:section_name) { 'test_section' } + let(:section_start_time) { Time.new(2017, 9, 20).utc } + let(:section_duration) { 3.seconds } + let(:section_end_time) { section_start_time + section_duration } + let(:section_start) { "section_start:#{section_start_time.to_i}:#{section_name}\r\033[0K"} + let(:section_end) { "section_end:#{section_end_time.to_i}:#{section_name}\r\033[0K"} + let(:section_start_html) do + '" + end + let(:section_end_html) do + '" + end + + it "prints light red" do + text = "#{section_start}\e[91mHello\e[0m\n#{section_end}" + html = %{#{section_start_html}Hello
#{section_end_html}} + + expect(convert_html(text)).to eq(html) + end + end + describe "truncates" do let(:text) { "Hello World" } let(:stream) { StringIO.new(text) } -- cgit v1.2.1