lib/danger_pronto/plugin.rb in danger-pronto-0.2.1 vs lib/danger_pronto/plugin.rb in danger-pronto-0.3.0

- old
+ new

@@ -12,45 +12,30 @@ # @tags pronto, linter # class DangerPronto < Plugin # Runs files through Pronto. Generates a `markdown` list of warnings. - # - # @param [String] files - # A globbed string which should return the files that you want to - # run though, defaults to nil. If nil, modified and added files from - # the diff will be used. - # @return [void] - # - def lint(files = nil) - files_to_lint = fetch_files_to_lint(files) + def lint(commit = nil) + files = pronto(commit) + return if files.empty? - return if offending_files.empty? - - markdown offenses_message(offending_files) + markdown offenses_message(files) end - # Gets the offending files from pronto - # @return [Array<Object>] Array of pronto warnings - def offending_files(files = nil) - files_to_lint = fetch_files_to_lint(files) - pronto(files_to_lint) - end - private # Executes pronto command - # - # @param [Array<String>] files_to_lint + # @param commit [String] hash/branch/tag # @return [Hash] Converted hash from pronto json output - # - def pronto(files_to_lint) - pronto_output = `#{'bundle exec ' if File.exists?('Gemfile')}pronto run -f json` + def pronto(specified_commit = nil) + commit = "origin/master" + commit = specified_commit if specified_commit.present? + pronto_output = `#{'bundle exec ' if File.exists?('Gemfile')}pronto run -f json -c #{commit}` JSON.parse(pronto_output) end - # Builds the t + # Builds the message def offenses_message(offending_files) require 'terminal-table' message = "### Pronto violations\n\n" table = Terminal::Table.new( @@ -59,17 +44,8 @@ rows: offending_files.map do |file| [file['path'], file['line'], file['message'], file['runner']] end ).to_s message + table.split("\n")[1..-2].join("\n") - end - - # Sets default files to modified and added files per commit - # @param [Array<String>] files Optional specific files to lint - # - # @return [Array<String>] Final files to lint - # - def fetch_files_to_lint(files = nil) - @files_to_lint ||= (files ? Dir.glob(files) : (git.modified_files + git.added_files)) end end end