Class: Gitlab::Ci::Ansi2json::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/ansi2json/converter.rb

Constant Summary collapse

TIMESTAMP_HEADER_REGEX =

Timestamp line prefix format: <timestamp> <stream number><stream type><full line type>

  • timestamp: UTC RFC3339 timestamp

  • stream number: 1 byte (2 hex chars) stream number

  • stream type: E/O (Err or Out)

  • full line type: ‘+` if line is continuation of previous line, ` ` otherwise

Gitlab::Ci::Trace::Stream::TIMESTAMP_HEADER_REGEX
TIMESTAMP_HEADER_DATETIME_LENGTH =
Gitlab::Ci::Trace::Stream::TIMESTAMP_HEADER_DATETIME_LENGTH
TIMESTAMP_HEADER_LENGTH =
Gitlab::Ci::Trace::Stream::TIMESTAMP_HEADER_LENGTH

Instance Method Summary collapse

Instance Method Details

#convert(stream, new_state) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gitlab/ci/ansi2json/converter.rb', line 17

def convert(stream, new_state)
  @lines = []
  @state = State.new(new_state, stream.size)
  @has_timestamps = nil

  append = false
  truncated = false

  cur_offset = stream.tell
  if cur_offset > @state.offset
    @state.offset = cur_offset
    truncated = true
  else
    stream.seek(@state.offset)
    append = @state.offset > 0
  end

  start_offset = @state.offset

  @state.new_line!(style: Style.new(**@state.inherited_style))

  process_stream_with_lookahead(stream)

  # This must be assigned before flushing the current line
  # or the @state.offset will advance to the very end
  # of the trace. Instead we want @last_line_offset to always
  # point to the beginning of last line.
  @state.set_last_line_offset

  flush_current_line

  Gitlab::Ci::Ansi2json::Result.new(
    lines: @lines,
    state: @state.encode,
    append: append,
    truncated: truncated,
    offset: start_offset,
    stream: stream
  )
end