lib/android_lint/plugin.rb in danger-android_lint-0.0.1 vs lib/android_lint/plugin.rb in danger-android_lint-0.0.2

- old
+ new

@@ -55,44 +55,54 @@ unless SEVERITY_LEVELS.include?(severity) fail("'#{severity}' is not a valid value for `severity` parameter.") return end + system "./gradlew #{gradle_task || 'lint'}" + unless File.exists?(REPORT_FILE) fail("Lint report not found at `#{REPORT_FILE}`. "\ "Have you forgot to add `xmlReport true` to your `build.gradle` file?") end - system "./gradlew #{gradle_task || 'lint'}" - issues = read_issues_from_report - message = message_for_issues(issues) - markdown(message) unless issues.empty? + filtered_issues = filter_issues_by_severity(issues) + + message = message_for_issues(filtered_issues) + markdown(message) unless filtered_issues.empty? end # A getter for `severity`, returning "Warning" if value is nil. # @return [String] def severity @severity || SEVERITY_LEVELS.first end private - def read_issues_from_report() + def read_issues_from_report file = File.open("app/build/reports/lint/lint-result.xml") require 'oga' report = Oga.parse_xml(file) report.xpath('//issue') end + def filter_issues_by_severity(issues) + issues.select do |issue| + severity_index(issue.get("severity")) >= severity_index(severity) + end + end + + def severity_index(severity) + SEVERITY_LEVELS.index(severity) || 0 + end + def message_for_issues(issues) message = "### AndroidLint found issues\n\n" - severity_index = SEVERITY_LEVELS.index(severity) || 0 - levels = SEVERITY_LEVELS.slice(severity_index, SEVERITY_LEVELS.size) - levels.reverse.each do |level| + SEVERITY_LEVELS.reverse.each do |level| filtered = issues.select{|issue| issue.get("severity") == level} message << parse_results(filtered, level) unless filtered.empty? end message