Sha256: 1af8aca8c5fc3d31c826e4ea2257acc81b89c4bd046ab0afb453fcb38d940323

Contents?: true

Size: 986 Bytes

Versions: 36

Compression:

Stored size: 986 Bytes

Contents

# 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

Version data entries

36 entries across 36 versions & 3 rubygems

Version Path
brakeman-5.4.1 lib/brakeman/report/report_github.rb
brakeman-lib-5.4.1 lib/brakeman/report/report_github.rb
brakeman-min-5.4.1 lib/brakeman/report/report_github.rb
brakeman-5.4.0 lib/brakeman/report/report_github.rb
brakeman-lib-5.4.0 lib/brakeman/report/report_github.rb
brakeman-min-5.4.0 lib/brakeman/report/report_github.rb
brakeman-5.3.1 lib/brakeman/report/report_github.rb
brakeman-lib-5.3.1 lib/brakeman/report/report_github.rb
brakeman-min-5.3.1 lib/brakeman/report/report_github.rb
brakeman-5.3.0 lib/brakeman/report/report_github.rb
brakeman-lib-5.3.0 lib/brakeman/report/report_github.rb
brakeman-min-5.3.0 lib/brakeman/report/report_github.rb
brakeman-5.2.3 lib/brakeman/report/report_github.rb
brakeman-lib-5.2.3 lib/brakeman/report/report_github.rb
brakeman-min-5.2.3 lib/brakeman/report/report_github.rb
brakeman-5.2.2 lib/brakeman/report/report_github.rb
brakeman-lib-5.2.2 lib/brakeman/report/report_github.rb
brakeman-min-5.2.2 lib/brakeman/report/report_github.rb
brakeman-5.2.1 lib/brakeman/report/report_github.rb
brakeman-lib-5.2.1 lib/brakeman/report/report_github.rb