lib/android_lint/plugin.rb in danger-android_lint-0.0.4 vs lib/android_lint/plugin.rb in danger-android_lint-0.0.5

- old
+ new

@@ -52,28 +52,31 @@ # Enable filtering # Only show messages within changed files. attr_accessor :filtering + # Skip gradle task + attr_accessor :skip_gradle_task + # Calls lint task of your gradle project. # It fails if `gradlew` cannot be found inside current directory. # It fails if `severity` level is not a valid option. # It fails if `xmlReport` configuration is not set to `true` in your `build.gradle` file. # @return [void] # def lint(inline_mode: false) - unless gradlew_exists? + if !skip_gradle_task && !gradlew_exists? fail("Could not find `gradlew` inside current directory") return end unless SEVERITY_LEVELS.include?(severity) fail("'#{severity}' is not a valid value for `severity` parameter.") return end - system "./gradlew #{gradle_task || 'lint'}" + system "./gradlew #{gradle_task || 'lint'}" unless skip_gradle_task 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 @@ -84,11 +87,11 @@ if inline_mode # Report with inline comment send_inline_comment(filtered_issues) else message = message_for_issues(filtered_issues) - markdown(message) unless filtered_issues.empty? + markdown("### AndroidLint found issues\n\n" + message) unless message.to_s.empty? end end # A getter for `severity`, returning "Warning" if value is nil. # @return [String] @@ -116,11 +119,11 @@ def severity_index(severity) SEVERITY_LEVELS.index(severity) || 0 end def message_for_issues(issues) - message = "### AndroidLint found issues\n\n" + message = "" SEVERITY_LEVELS.reverse.each do |level| filtered = issues.select{|issue| issue.get("severity") == level} message << parse_results(filtered, level) unless filtered.empty? end @@ -129,22 +132,26 @@ end def parse_results(results, heading) target_files = (git.modified_files - git.deleted_files) + git.added_files dir = "#{Dir.pwd}/" - message = "#### #{heading} (#{results.count})\n\n" + count = 0; + message = "" - message << "| File | Line | Reason |\n" - message << "| ---- | ---- | ------ |\n" - results.each do |r| location = r.xpath('location').first filename = location.get('file').gsub(dir, "") next unless !filtering || (target_files.include? filename) line = location.get('line') || 'N/A' reason = r.get('message') - + count = count + 1 message << "`#{filename}` | #{line} | #{reason} \n" + end + if count != 0 + header = "#### #{heading} (#{count})\n\n" + header << "| File | Line | Reason |\n" + header << "| ---- | ---- | ------ |\n" + message = header + message end message end