Skip to content

Instantly share code, notes, and snippets.

@coryodaniel
Created August 5, 2016 22:35
Show Gist options
  • Save coryodaniel/96283c984801ca9b4192aaa85889fd52 to your computer and use it in GitHub Desktop.
Save coryodaniel/96283c984801ca9b4192aaa85889fd52 to your computer and use it in GitHub Desktop.
Rake task to flog your rails commits for CI
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