Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. files = []
  4. waiting = true
  5. threads = []
  6. lines = []
  7.  
  8. ignore = [
  9. 'db/schema.rb'
  10. ]
  11.  
  12. files += `git diff --name-only --cached`.split("\n")
  13. if files.size.zero?
  14. puts 'no files staged'
  15. exit 1
  16. end
  17. files.reject! { |x| ignore.include?(x) }
  18. puts 'Checking changes'
  19. files.each do |file|
  20. puts file
  21. end
  22.  
  23. exit 0 if files.size.zero?
  24.  
  25. threads << Thread.new do
  26. index = 0
  27. chars = %w[| / - \\]
  28. while waiting
  29. print "codeclimate analyzing ... #{chars[(index += 1) % chars.length]}\r"
  30. sleep(1)
  31. end
  32. puts 'codeclimate analyzing ... done'
  33. end
  34.  
  35. threads << Thread.new do
  36. lines = %x(codeclimate analyze #{files.join(' ')})
  37. waiting = false
  38. end
  39. threads.map(&:join)
  40.  
  41. lines.split("\n").each { |l| puts(l) }
  42. exit true if lines.include?('Found 0 issues')
  43.  
  44. # Open input from keyboard usin IO.new(0) normal standard in is closed
  45. fd = IO.sysopen "/dev/tty", "r"
  46. ios = IO.new(fd, "r")
  47.  
  48. print 'Do you want to commit anyway?(Y) '
  49. exit ios.gets.chomp == 'Y'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement