Created
August 5, 2016 22:35
-
-
Save coryodaniel/96283c984801ca9b4192aaa85889fd52 to your computer and use it in GitHub Desktop.
Rake task to flog your rails commits for CI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :ci do | |
desc "Flog it" | |
task :flog do | |
max_score = 10.0 | |
changed_files = `git diff develop --name-only | grep "app/" | grep ".rb" | tr '\n' ' '`.split(' ') | |
if changed_files.any? | |
avg_score = `flog -g -s #{changed_files.join(' ')} | tail -n 1` | |
score = avg_score.match( /(\d+\.\d+)/)[0].to_f | |
if score > max_score | |
puts `git diff develop --name-only | grep "app/" | grep ".rb" | tr '\n' ' ' | xargs flog -g` | |
puts "Flog score (#{score}) exceeded max (#{max_score}). Clean up some code!" | |
exit(1) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment