Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
tessereth committed Apr 29, 2018
1 parent d9a6e93 commit ed9bb6c
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 24 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ Other formatter options are:

* `context:` The Buildkite annotation context. Defaults to `test-summary`.
* `style:` Set the annotation style. Defaults to `error`.
* `job_id_regex`: Ruby regular expression to extract the `job_id` from the artifact path. It must contain
a named capture with the name `job_id`. Defaults to
`(?<job_id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})`.

## Developing

Expand Down
21 changes: 17 additions & 4 deletions lib/test_summary_buildkite_plugin/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(options = {})

def markdown(input)
return nil if input.failures.count.zero?
"#{heading(input)}\n\n#{input_markdown(input)}"
[heading(input), input_markdown(input), footer(input)].compact.join("\n\n")
end

def input_markdown(input)
Expand All @@ -28,25 +28,38 @@ def input_markdown(input)
end

def failures_markdown(failures)
engine = Haml::Engine.new(File.read("templates/#{type}/failures.html.haml"))
engine.render(Object.new, failures: failures)
render_template('failures', failures: failures)
end

def heading(input)
count = input.failures.count
"##### #{input.label}: #{count} failure#{'s' unless count == 1}"
end

def footer(input)
job_ids = input.failures.map(&:job_id).uniq.reject(&:nil?)
render_template('footer', job_ids: job_ids)
end

def show_first
options[:show_first] || 20
end

def details(summary, contents)
"<details><summary>#{summary}</summary>\n#{contents}\n</details>"
# The empty paragraph puts padding between the details and the following element
"<details><summary>#{summary}</summary>\n#{contents}\n</details><p></p>"
end

def type
options[:type] || 'details'
end

def render_template(name, params)
filename = %W[templates/#{type}/#{name}.html.haml templates/#{name}.html.haml].find { |f| File.exist?(f) }
if filename
engine = Haml::Engine.new(File.read(filename))
engine.render(Object.new, params)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/usr/src/app/javascript/src/foo.js:8:25: Delete `⏎···` [Error/prettier/prettier]
/usr/src/app/javascript/src/bar.js::4:10: 'List' is defined but never used. [Error/no-unused-vars]

1 problem
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="rspec" tests="1" skipped="0" failures="1" errors="0" time="9.658348" timestamp="2018-04-24T14:55:21+10:00" hostname="foo.local">
<testcase classname="spec.features.test_things_spec" name="test all the things" file="./spec/features/test_things_spec.rb" time="2.068429"><failure message="broken" type="RuntimeError">Failure/Error: fail(&apos;whatever&apos;)

RuntimeError:
whatever
./spec/features/test_things_spec.rb:5:in `block (3 levels) in &lt;top (required)&gt;&apos;</failure></testcase>
</testsuite>
2 changes: 1 addition & 1 deletion spec/test_summary_buildkite_plugin/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
let(:artifact_path) { 'rspec*' }

it 'has all failures' do
expect(input.failures.count).to eq(5)
expect(input.failures.count).to eq(6)
end

it 'sorts failures' do
Expand Down
20 changes: 8 additions & 12 deletions templates/details/failures.html.haml
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
- jobs = failures.map(&:job_id).uniq.reject { |job| job == nil }
- if jobs.count == 1
Job:
%a{href: "##{jobs.first}"}
= jobs.first

%ul
- failures.each do |failure|
%li
- if failure.details
- if failure.details || failure.job_id
%details
%summary
%code
= failure.summary
%pre
%code
= failure.details
- unless failure.job_id.nil? || jobs.count == 1
- if failure.details
%pre
%code
= failure.details
- if failure.job_id
%p
Job:
in
%a{href: "##{failure.job_id}"}
job
= failure.job_id
- else
%code
Expand Down
7 changes: 0 additions & 7 deletions templates/summary/failures.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
%pre
%code
= failures.map(&:summary).join("\n")

- jobs = failures.map(&:job_id).uniq.reject { |job| job == nil }
- unless jobs.empty?
Jobs:
- jobs.each do |job_id|
%a{href: "##{job_id}"}
= job_id
11 changes: 11 additions & 0 deletions templates/summary/footer.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-# Note: we need to use markdown links here rather than <a>'s otherwise the markdown renderer adds incorrect spacing
- unless job_ids.empty?
See
- job_ids[0...-2].each do |job_id|
= "[job #{job_id}](##{job_id}),"

- if job_ids.count > 1
= "[job #{job_ids[-2]}](##{job_ids[-2]})"
and

= "[job #{job_ids.last}](##{job_ids.last})"

0 comments on commit ed9bb6c

Please sign in to comment.