Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1580 from klausbadelt/github-reporter
Github Actions output format
- Loading branch information
Showing
7 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Github Actions Formatter | ||
# Formats warnings as workflow commands to create annotations in GitHub UI | ||
class Brakeman::Report::Github < Brakeman::Report::Base | ||
def generate_report | ||
# @see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message | ||
errors.concat(warnings).join("\n") | ||
end | ||
|
||
def warnings | ||
all_warnings | ||
.map { |warning| "::warning file=#{warning_file(warning)},line=#{warning.line}::#{warning.message}" } | ||
end | ||
|
||
def errors | ||
tracker.errors.map do |error| | ||
if error[:exception].is_a?(Racc::ParseError) | ||
# app/services/balance.rb:4 :: parse error on value "..." (tDOT3) | ||
file, line = error[:exception].message.split(':').map(&:strip)[0,2] | ||
"::error file=#{file},line=#{line}::#{clean_message(error[:error])}" | ||
else | ||
"::error ::#{clean_message(error[:error])}" | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def clean_message(msg) | ||
msg.gsub('::','').squeeze(' ') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require_relative '../test' | ||
|
||
class TestGithubOutput < Minitest::Test | ||
def setup | ||
@@report ||= github_report | ||
end | ||
|
||
def test_report_format | ||
assert_equal 33, @@report.lines.count | ||
@@report.lines.each do |line| | ||
assert line.start_with?('::'), 'Every line must start with `::`' | ||
assert_equal 2, line.scan('::').count, 'Every line must have exactly 2 `::`' | ||
end | ||
end | ||
|
||
def test_for_errors | ||
assert_equal 2, @@report.lines.count {|line| line.start_with?('::error') } | ||
assert_includes @@report, 'file=app/services/balance.rb,line=4' | ||
end | ||
|
||
private | ||
|
||
def github_report | ||
tracker = Brakeman.run("#{TEST_PATH}/apps/rails6") | ||
tracker.error Racc::ParseError.new('app/services/balance.rb:4 :: parse error on value "..." (tDOT3)') | ||
tracker.error StandardError.new('Something went wrong') | ||
tracker.report.to_github | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters