lib/android_lint/plugin.rb in danger-android_lint-0.0.7 vs lib/android_lint/plugin.rb in danger-android_lint-0.0.8

- old
+ new

@@ -11,10 +11,15 @@ # @example Running AndroidLint with a specific gradle task # # android_lint.gradle_task = "lintMyFlavorDebug" # android_lint.lint # + # @example Running AndroidLint without running a Gradle task + # + # android_lint.skip_gradle_task = true + # android_lint.lint + # # @example Running AndroidLint for a specific severity level and up # # # options are ["Warning", "Error", "Fatal"] # android_lint.severity = "Error" # android_lint.lint @@ -29,10 +34,11 @@ # Location of lint report file # If your Android lint task outputs to a different location, you can specify it here. # Defaults to "app/build/reports/lint/lint-result.xml". # @return [String] attr_accessor :report_file + # A getter for `report_file`. # @return [String] def report_file return @report_file || 'app/build/reports/lint/lint-result.xml' end @@ -41,63 +47,83 @@ # This is useful when your project has different flavors. # Defaults to "lint". # @return [String] attr_accessor :gradle_task + # A getter for `gradle_task`, returning "lint" if value is nil. + # @return [String] + def gradle_task + @gradle_task ||= "lint" + end + + # Skip Gradle task. + # This is useful when Gradle task has been already executed. + # Defaults to `false`. + # @return [Bool] + attr_writer :skip_gradle_task + + # A getter for `skip_gradle_task`, returning `false` if value is nil. + # @return [Boolean] + def skip_gradle_task + @skip_gradle_task ||= false + end + # Defines the severity level of the execution. # Selected levels are the chosen one and up. # Possible values are "Warning", "Error" or "Fatal". # Defaults to "Warning". # @return [String] attr_writer :severity + # A getter for `severity`, returning "Warning" if value is nil. + # @return [String] + def severity + @severity || SEVERITY_LEVELS.first + end + # 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) - if !skip_gradle_task && !gradlew_exists? - fail("Could not find `gradlew` inside current directory") - return + unless skip_gradle_task + return fail("Could not find `gradlew` inside current directory") unless gradlew_exists? end unless SEVERITY_LEVELS.include?(severity) fail("'#{severity}' is not a valid value for `severity` parameter.") return end - system "./gradlew #{gradle_task || 'lint'}" unless skip_gradle_task + unless skip_gradle_task + system "./gradlew #{gradle_task}" + end 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 issues = read_issues_from_report filtered_issues = filter_issues_by_severity(issues) + message = "" + if inline_mode # Report with inline comment send_inline_comment(filtered_issues) else message = message_for_issues(filtered_issues) 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] - def severity - @severity || SEVERITY_LEVELS.first + + message end private def read_issues_from_report