Skip to content

Commit

Permalink
Merge pull request #36 from bugcrowd/timnew-add-checkstyle-suppport
Browse files Browse the repository at this point in the history
Add support for checkstyle

This is #34 just with some minor tweaks
  • Loading branch information
Tessa Bradbury authored Sep 26, 2018
2 parents 564a26f + b6fd743 commit 495bc5b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ steps:
- label: ":rubocop: rubocop"
artifact_path: spec/sample_artifacts/rubocop.txt
type: oneline
- label: ":greencheck: checkstyle"
artifact_path: spec/sample_artifacts/checkstyle.xml
type: checkstyle
formatter:
type: summary
show_first: 3
Expand Down Expand Up @@ -102,6 +105,9 @@ steps:
- label: ":rubocop: rubocop"
artifact_path: spec/sample_artifacts/rubocop.txt
type: oneline
- label: ":greencheck: checkstyle"
artifact_path: spec/sample_artifacts/checkstyle.xml
type: checkstyle
formatter:
type: details
show_first: 3
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ for all your test failures using
Supported formats:

* JUnit
* Checkstyle
* [TAP](https://testanything.org)^
* Plain text files with one failure per line

Expand All @@ -30,6 +31,10 @@ steps:
# end
artifact_paths: "artifacts/*"

- label: eslint
command: yarn run eslint -f checkstyle -o artifacts/eslint.xml
artifact_paths: "artifacts/*"

- label: ava
command: bash -c "yarn --silent test --tap > artifacts/ava.tap"
artifact_paths: "artifacts/*"
Expand Down Expand Up @@ -57,6 +62,9 @@ Add a build step using the test-summary plugin:
- label: rspec
artifact_path: artifacts/rspec*
type: junit
- label: eslint
artifact_path: artifacts/eslint.xml
type: checkstyle
- label: ava
artifact_path: artifacts/ava.tap
type: tap
Expand All @@ -78,7 +86,7 @@ The plugin takes a list of input sources. Each input source has:
* `label:` the name used in the heading to identify the test group.
* `artifact_path:` a glob used to download one or more artifacts.
* `type:` one of `junit`, `tap` or `oneline`.
* `type:` one of `junit`, `checkstyle`, `tap` or `oneline`.
* `encoding:` The file encoding to use. Defaults to `UTF-8`.
* `strip_colors:` Remove ANSI color escape sequences. Defaults to `false`.
* `crop:` (`oneline` type only) Number of lines to crop from the start and end of the file,
Expand Down
29 changes: 28 additions & 1 deletion lib/test_summary_buildkite_plugin/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,37 @@ def details(yaml_lines)
end
end

class Checkstyle < Base
def file_contents_to_failures(str)
xml = REXML::Document.new(str)
xml.elements.enum_for(:each, '//file').flat_map do |file|
filename = file.attribute('name').value

file.elements.map do |error|
Failure::Structured.new(
summary: summary(filename, error),
details: error.attribute('source').value
)
end
end
end

def summary(filename, error)
severity = error.attribute('severity').value
line = error.attribute('line').value
column = error.attribute('column').value
location = "#{filename}:#{line}:#{column}"
message = error.attribute('message').value

"[#{severity}] #{location}: #{message}"
end
end

TYPES = {
oneline: Input::OneLine,
junit: Input::JUnit,
tap: Input::Tap
tap: Input::Tap,
checkstyle: Input::Checkstyle
}.freeze
end
end
1 change: 1 addition & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ configuration:
type: string
enum:
- junit
- checkstyle
- tap
- oneline
encoding:
Expand Down
6 changes: 6 additions & 0 deletions spec/sample_artifacts/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<checkstyle version="8.0">
<file name="src/main/java/io/timnew/sol/Sol.kt">
<error line="106" column="1" severity="error" message="Needless blank line(s)" source="no-consecutive-blank-lines" />
</file>
</checkstyle>
21 changes: 21 additions & 0 deletions spec/test_summary_buildkite_plugin/input_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,27 @@
end
end

describe 'checkstyle' do
let(:type) { 'checkstyle' }
let(:artifact_path) { 'checkstyle.xml' }

it { is_expected.to be_a(TestSummaryBuildkitePlugin::Input::Checkstyle) }

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

it 'failures have summary' do
expect(input.failures.first.summary).to eq(
'[error] src/main/java/io/timnew/sol/Sol.kt:106:1: Needless blank line(s)'
)
end

it 'failures have details' do
expect(input.failures.first.details).to include 'no-consecutive-blank-lines'
end
end

describe 'setting ascii encoding' do
let(:type) { 'oneline' }
let(:artifact_path) { 'eslint-00112233-0011-0011-0011-001122334455.txt' }
Expand Down

0 comments on commit 495bc5b

Please sign in to comment.