Skip to content

Commit 83b6033

Browse files
morizyunsds
authored andcommittedMay 12, 2016
Add to run bundle outdated in pre commit
1 parent a46dcf2 commit 83b6033

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ issue](https://github.com/brigade/overcommit/issues/238) for more details.
468468
* [Brakeman](lib/overcommit/hook/pre_commit/brakeman.rb)
469469
* [`*`BrokenSymlinks](lib/overcommit/hook/pre_commit/broken_symlinks.rb)
470470
* [BundleCheck](lib/overcommit/hook/pre_commit/bundle_check.rb)
471+
* [BundleOutdated](lib/overcommit/hook/pre_commit/bundle_outdated.rb)
471472
* [`*`CaseConflicts](lib/overcommit/hook/pre_commit/case_conflicts.rb)
472473
* [ChamberSecurity](lib/overcommit/hook/pre_commit/chamber_security.rb)
473474
* [CoffeeLint](lib/overcommit/hook/pre_commit/coffee_lint.rb)

‎config/default.yml

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ PreCommit:
175175
- 'Gemfile.lock'
176176
- '*.gemspec'
177177

178+
BundleOutdated:
179+
enabled: false
180+
description: 'List installed gems with newer versions available'
181+
required_executable: 'bundle'
182+
flags: ['outdated', '--strict', '--parseable']
183+
install_command: 'gem install bundler'
184+
178185
CaseConflicts:
179186
enabled: true
180187
description: 'Check for case-insensitivity conflicts'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Overcommit::Hook::PreCommit
2+
# Check if local Gemfile.lock matches Gemfile when either changes, unless
3+
# Gemfile.lock is ignored by git.
4+
# Check outdated rubyGems
5+
#
6+
# @see http://bundler.io/bundle_outdated.html
7+
class BundleOutdated < Base
8+
LOCK_FILE = 'Gemfile.lock'.freeze
9+
10+
def run
11+
# Ignore if Gemfile.lock is not tracked by git
12+
ignored_files = execute(%w[git ls-files -o -i --exclude-standard]).stdout.split("\n")
13+
return :pass if ignored_files.include?(LOCK_FILE)
14+
15+
result = execute(command)
16+
warn_msgs = result.stdout.split("\n").
17+
reject { |str| str.strip.empty? }.
18+
reject { |str| (str.strip =~ /^(\[|\()?warning|deprecation/i) }
19+
warnings = warn_msgs.map { |msg| Overcommit::Hook::Message.new(:warning, nil, nil, msg) }
20+
21+
warnings.empty? ? :pass : warnings
22+
end
23+
end
24+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PreCommit::BundleOutdated do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
context 'when Gemfile.lock is ignored' do
9+
around do |example|
10+
repo do
11+
touch 'Gemfile.lock'
12+
echo('Gemfile.lock', '.gitignore')
13+
`git add .gitignore`
14+
`git commit -m "Ignore Gemfile.lock"`
15+
example.run
16+
end
17+
end
18+
19+
it { should pass }
20+
end
21+
22+
context 'when Gemfile.lock is not ignored' do
23+
around do |example|
24+
repo do
25+
example.run
26+
end
27+
end
28+
29+
before do
30+
subject.stub(:execute).with(%w[git ls-files -o -i --exclude-standard]).
31+
and_return(double(stdout: ''))
32+
subject.stub(:execute).with(%w[bundle outdated --strict --parseable]).
33+
and_return(result)
34+
end
35+
36+
context 'and it reports some outdated gems' do
37+
let(:result) do
38+
double(stdout: <<-EOF
39+
Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
40+
41+
airbrake (newest 5.3.0, installed 5.2.3, requested ~> 5.0)
42+
aws-sdk (newest 2.3.3, installed 2.3.1, requested ~> 2)
43+
font-awesome-rails (newest 4.6.2.0, installed 4.6.1.0)
44+
mechanize (newest 2.7.4, installed 2.1.1)
45+
minimum-omniauth-scaffold (newest 0.4.3, installed 0.4.1)
46+
airbrake-ruby (newest 1.3.0, installed 1.2.4)
47+
aws-sdk-core (newest 2.3.3, installed 2.3.1)
48+
aws-sdk-resources (newest 2.3.3, installed 2.3.1)
49+
config (newest 1.1.1, installed 1.1.0)
50+
ruby_parser (newest 3.8.2, installed 3.8.1)
51+
EOF
52+
)
53+
end
54+
55+
it { should warn }
56+
end
57+
58+
context 'and it reports bundle up to date' do
59+
let(:result) do
60+
double(stdout: <<-EOF
61+
Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
62+
63+
EOF
64+
)
65+
end
66+
67+
it { should pass }
68+
end
69+
end
70+
end

0 commit comments

Comments
 (0)