Skip to content

Commit

Permalink
Merge pull request #8 from mattlqx/test
Browse files Browse the repository at this point in the history
Minor fixes to prevent cookstyle running on too large of scope
  • Loading branch information
mattlqx authored Jan 20, 2020
2 parents 70dc069 + 318a81e commit a887466
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
entry: bin/cookstyle-wrapper.rb
language: script
pass_filenames: true
types: ['file']
types: ['ruby']
verbose: true
require_serial: true
- id: chef-cookbook-version
name: Ensure Chef cookbook version bump
description: Ensure Chef cookbook versions are bumped when contents are changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To check Chef cookbook version bumps, use the `chef-cookbook-version` hook. Each
To unit test Ruby changes in your repo, use the `rspec` hook. Each path in your repo with a `spec` directory should have a `Gemfile` that includes your desired version of rspec (or a derivative library). It will be installed via Bundler prior to testing. Rspec will only be run against the closest directory in a changed file's path with a spec dir.

- repo: https://github.com/mattlqx/pre-commit-ruby
rev: v1.3.0
rev: v1.3.1
hooks:
- id: rubocop
- id: foodcritic
Expand Down
5 changes: 3 additions & 2 deletions bin/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ def bump_required?(file)
end == true
end

def changed_cookbooks(bump_check: true)
def changed_cookbooks(paths = nil, bump_check: true)
changed_cookbooks = []
ARGV.each do |file|
paths ||= ARGV
paths.each do |file|
cookbook, type = metadata_walk(file)
next if cookbook == false || changed_cookbooks.map(&:first).include?(cookbook) || file.include?('/test/')

Expand Down
2 changes: 1 addition & 1 deletion bin/cookstyle-wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# Exit early if there are no paths to lint
success = true
exit(success) if changed_cookbooks(bump_check: false).empty?
exit(success) if changed_cookbooks(bump_check: false).compact.empty?

# Install cookstyle and drop args that are paths
system('bundle install >/dev/null') || exit(false)
Expand Down

0 comments on commit a887466

Please sign in to comment.