class Warnings::Reporter
Base reporter class to define attributes and common method to create a report.
Constants
- DEFAULT_FAIL
- DEFAULT_FILTER
- DEFAULT_INLINE
- DEFAULT_NAME
- ERROR_FILE_NOT_SET
- ERROR_HIGH_SEVERITY
- ERROR_PARSER_NOT_SET
Attributes
Defines the baseline of file paths if needed. @example src/main/java
@return [String] Path baseline for git files.
Whether to fail the PR if any high issue is reported.
@return [Bool] Fail on high issues.
The file path to parse.
@return [String] Path to file.
Whether to filter and report only for changes files. If this is set to false, all issues are of a report are included in the comment.
@return [Bool] Filter for changes files.
Whether to comment a markdown report or do an inline comment on the file.
@return [Bool] Use inline comments.
The name of this reporter. It is used to identify your report in the comments.
The parser to be used to read issues out of the file.
@return [Symbol] Name of the parser.
The generated implementation of the :parser.
@return [Parser] Parser
implementation
Public Class Methods
# File lib/warnings/report/reporter.rb, line 49 def initialize(danger) @danger = danger @inline = DEFAULT_INLINE @filter = DEFAULT_FILTER @fail_error = DEFAULT_FAIL @issues = [] end
Public Instance Methods
Return the name of this reporter. The name can have 3 values:
- The name set using #name= - If name is not set, the name of the parser - If name and parser are not set, a DEFAULT_NAME
@return [String] Name of the reporter.
# File lib/warnings/report/reporter.rb, line 82 def name result = @name result ||= "#{@parser_impl.name} #{DEFAULT_NAME}" if @parser_impl result || DEFAULT_NAME end
Define the parser to be used.
@@raise If no implementation can be found for the symbol. @param value [Symbol] A symbol key to match a parser implementation.
# File lib/warnings/report/reporter.rb, line 70 def parser=(value) @parser = value @parser_impl = ParserFactory.create(value) end
Start generating the report. Evaluate, parse and comment the found issues.
# File lib/warnings/report/reporter.rb, line 59 def report validate parse filter_issues comment end
Private Instance Methods
# File lib/warnings/report/reporter.rb, line 118 def comment return if @issues.empty? inline ? inline_comment : markdown_comment end
# File lib/warnings/report/reporter.rb, line 90 def filter_issues return unless filter git_files = @danger.git.modified_files + @danger.git.added_files @issues.select! do |issue| git_files.include?(issue_filename(issue)) end end
# File lib/warnings/report/reporter.rb, line 149 def high_issue?(issue) issue.severity.eql?(:high) end
# File lib/warnings/report/reporter.rb, line 141 def high_issues? result = false @issues.each do |issue| result = true if high_issue?(issue) end result end
# File lib/warnings/report/reporter.rb, line 124 def inline_comment @issues.each do |issue| text = MessageUtil.inline(issue) if fail_error && high_issue?(issue) @danger.fail(text, line: issue.line, file: issue.file_name) else @danger.warn(text, line: issue.line, file: issue.file_name) end end end
# File lib/warnings/report/reporter.rb, line 99 def issue_filename(item) result = '' if baseline result << baseline result << '/' unless baseline.chars.last == '/' end result << item.file_name end
# File lib/warnings/report/reporter.rb, line 135 def markdown_comment text = MessageUtil.markdown(name, @issues) @danger.markdown(text) @danger.fail(format(ERROR_HIGH_SEVERITY, name)) if fail_error && high_issues? end
# File lib/warnings/report/reporter.rb, line 113 def parse @parser_impl.parse(file) @issues = @parser_impl.issues end
# File lib/warnings/report/reporter.rb, line 108 def validate raise ERROR_PARSER_NOT_SET if @parser_impl.nil? raise ERROR_FILE_NOT_SET if @file.nil? end