Skip to content

Commit

Permalink
Add RuboCop git hook
Browse files Browse the repository at this point in the history
[#155618738](https://www.pivotaltracker.com/story/show/155618738)

Co-authored-by: Sebastian Heid <sebastian.heid@sap.com>
  • Loading branch information
beyhan and s4heid committed Mar 21, 2018
1 parent 8b36506 commit ea8f2b6
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions git-hooks/pre-commit
@@ -0,0 +1,2 @@
unset GIT_DIR
scripts/rubocop-staged
17 changes: 17 additions & 0 deletions scripts/install-git-hooks
@@ -0,0 +1,17 @@
#!/bin/bash

ROOT_DIR=$(cd $(dirname $0)/.. && pwd)
PRE_COMMIT=${ROOT_DIR}/.git/hooks/pre-commit

if [ ! -f ${PRE_COMMIT} ]; then
echo "#!/bin/bash" > ${PRE_COMMIT}
chmod +x ${PRE_COMMIT}
fi

if grep -q 'git-hooks/pre-commit' ${PRE_COMMIT}; then
echo "pre-commit already installed."
else
echo >> ${PRE_COMMIT}
echo './git-hooks/pre-commit' >> ${PRE_COMMIT}
echo "pre-commit installed."
fi
12 changes: 12 additions & 0 deletions scripts/rubocop-staged
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'English'

Dir.chdir(File.expand_path(__dir__ + '/../src/bosh_openstack_cpi')) do
command = 'bundle exec rubocop-git --cached'
puts("Running '#{command}'")
system(command)
end

exit $CHILD_STATUS.exitstatus
8 changes: 8 additions & 0 deletions scripts/test-unit
@@ -0,0 +1,8 @@
#!/bin/bash

"$(dirname $0)/install-git-hooks"

pushd "$(dirname $0)/../src/bosh_openstack_cpi"
bundle install
bundle exec rspec spec/unit
popd
2 changes: 2 additions & 0 deletions src/bosh_openstack_cpi/Gemfile
Expand Up @@ -13,6 +13,8 @@ group :development, :test do
gem 'rake', '~>10.3.2'
gem 'rspec', '~> 3.3.0'
gem 'rspec-its', '~> 1.0.1'
gem 'rubocop'
gem 'rubocop-git'
gem 'timecop', '~>0.7.1'
gem 'webmock', '~>2.3.2'
end
21 changes: 20 additions & 1 deletion src/bosh_openstack_cpi/Gemfile.lock
Expand Up @@ -3,6 +3,7 @@ GEM
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
bosh_common (1.3262.24.0)
logging (~> 1.8.2)
semi_semantic (~> 1.2.0)
Expand Down Expand Up @@ -38,7 +39,12 @@ GEM
minitar (0.5.4)
multi_json (1.13.1)
netaddr (1.5.1)
parallel (1.12.1)
parser (2.5.0.4)
ast (~> 2.4.0)
powerpack (0.1.1)
public_suffix (3.0.2)
rainbow (3.0.0)
rake (10.3.2)
rspec (3.3.0)
rspec-core (~> 3.3.0)
Expand All @@ -56,9 +62,20 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
rubocop (0.54.0)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
rubocop-git (0.1.3)
rubocop (>= 0.24.1)
ruby-progressbar (1.9.0)
safe_yaml (1.0.4)
semi_semantic (1.2.0)
timecop (0.7.4)
unicode-display_width (1.3.0)
webmock (2.3.2)
addressable (>= 2.3.6)
crack (>= 0.3.2)
Expand All @@ -79,8 +96,10 @@ DEPENDENCIES
rake (~> 10.3.2)
rspec (~> 3.3.0)
rspec-its (~> 1.0.1)
rubocop
rubocop-git
timecop (~> 0.7.1)
webmock (~> 2.3.2)

BUNDLED WITH
1.16.0
1.16.1

0 comments on commit ea8f2b6

Please sign in to comment.