Skip to content

Commit

Permalink
Allow specifying a path on which to pronto run
Browse files Browse the repository at this point in the history
Example `pronto run -f github lib/pronto/github.rb`
  • Loading branch information
mmozuras committed Nov 29, 2014
1 parent f640800 commit 3beccc6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Try to detect pull request id automatically, if `PULL_REQUEST_ID` is not specified. Inspired by @willnet/prid.
* [#40](https://github.com/mmozuras/pronto/issues/40): Add '--index' option for 'pronto run'. Pronto analyzes changes before committing.
* [#50](https://github.com/mmozuras/pronto/pull/50): Adds GitLab formatter
* [#52](https://github.com/mmozuras/pronto/pull/52): Allow specifying a path for 'pronto run'.

### Changes
* Github and Github pull request formatters now filter out duplicate offenses on the same line to avoid spamming with redundant comments.
Expand Down
11 changes: 4 additions & 7 deletions lib/pronto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
require 'pronto/formatter/formatter'

module Pronto
def self.run(commit = 'master', repo_path = '.', formatter = nil)
def self.run(commit = 'master', repo_path = '.',
formatter = Formatter::TextFormatter.new, file = nil)
commit ||= 'master'

repo = Git::Repository.new(repo_path)
patches = repo.diff(commit)
options = { paths: [file] } if file
patches = repo.diff(commit, options)

result = run_all_runners(patches)

formatter ||= default_formatter
puts formatter.format(result, repo)

result
Expand Down Expand Up @@ -59,8 +60,4 @@ def self.run_all_runners(patches)
runner.new.run(patches, patches.commit)
end.flatten.compact
end

def default_formatter
Formatter::TextFormatter.new
end
end
4 changes: 2 additions & 2 deletions lib/pronto/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def is_thor_reserved_word?(word, type)
aliases: '-f',
banner: "Pick output formatter. Available: #{::Pronto::Formatter.names.join(', ')}"

def run
def run(path = nil)
gem_names = options[:runner].any? ? options[:runner] : ::Pronto.gem_names
gem_names.each do |gem_name|
require "pronto/#{gem_name}"
end

formatter = ::Pronto::Formatter.get(options[:formatter])
commit = options[:index] ? :index : options[:commit]
messages = ::Pronto.run(commit, '.', formatter)
messages = ::Pronto.run(commit, '.', formatter, path)
exit(messages.count) if options[:'exit-code']
rescue Rugged::RepositoryError
puts '"pronto" should be run from a git repository'
Expand Down
6 changes: 3 additions & 3 deletions lib/pronto/git/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def initialize(path)
@repo = Rugged::Repository.new(path)
end

def diff(commit)
def diff(commit, options = nil)
if commit == :index
patches = @repo.index.diff
patches = @repo.index.diff(options)
Patches.new(self, head, patches)
else
merge_base = merge_base(commit)
patches = @repo.diff(merge_base, head)
patches = @repo.diff(merge_base, head, options)
Patches.new(self, merge_base, patches)
end
end
Expand Down

0 comments on commit 3beccc6

Please sign in to comment.