Skip to content

Commit 1d02d9c

Browse files
committed
Use REXML::Element#texts instead
1 parent 7afe485 commit 1d02d9c

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

ruby/bin/annotate

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,6 @@
33
require 'rexml/document'
44
require 'rexml/element'
55

6-
# Adapted from https://stackoverflow.com/a/25888239/759019
7-
class REXML::Element
8-
def innerHTML=(xml)
9-
require "rexml/document"
10-
self.to_a.each do |e|
11-
self.delete e
12-
end
13-
d = REXML::Document.new "<root>#{xml}</root>"
14-
d.root.to_a.each do |e|
15-
case e
16-
when REXML::Text
17-
self.add_text e
18-
when REXML::Element
19-
self.add_element e
20-
else
21-
puts "ERROR"
22-
end
23-
end
24-
xml
25-
end
26-
def inner_html
27-
ret = ''
28-
self.to_a.each do |e|
29-
ret += e.to_s
30-
end
31-
ret
32-
end
33-
end
34-
356
# Reads a list of junit files and returns a nice Buildkite build annotation on
367
# STDOUT that summarizes any failures.
378

@@ -51,6 +22,16 @@ end
5122
junit_report_files = Dir.glob(File.join(junits_dir, "**", "*"))
5223
failures = []
5324

25+
def text_content(element)
26+
# Handle mulptiple CDATA/text children elements
27+
text = element.texts().map(&:value).join.strip
28+
if text.empty?
29+
nil
30+
else
31+
text
32+
end
33+
end
34+
5435
junit_report_files.sort.each do |file|
5536
next if File.directory?(file)
5637

@@ -63,10 +44,10 @@ junit_report_files.sort.each do |file|
6344
name = testcase.attributes['name'].to_s
6445
failed_test = testcase.attributes[failure_format].to_s
6546
testcase.elements.each("failure") do |failure|
66-
failures << Failure.new(name, failed_test, failure.inner_html, job, :failure)
47+
failures << Failure.new(name, failed_test, text_content(failure), job, :failure)
6748
end
6849
testcase.elements.each("error") do |error|
69-
failures << Failure.new(name, failed_test, error.inner_html, job, :error)
50+
failures << Failure.new(name, failed_test, text_content(error), job, :error)
7051
end
7152
end
7253
end

0 commit comments

Comments
 (0)