Guest User

Untitled

a guest
Dec 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Check for ruby style errors
  4.  
  5. red='\033[0;31m'
  6. green='\033[0;32m'
  7. yellow='\033[0;33m'
  8. NC='\033[0m'
  9.  
  10. if git rev-parse --verify HEAD >/dev/null 2>&1
  11. then
  12. against=HEAD
  13. else
  14. echo "Initial commit: diff against an empty tree object"
  15. fi
  16.  
  17. # Check if rubocop is installed for the current project
  18. rubocop -v >/dev/null 2>&1 || { echo >&2 "${red}[Ruby Style][Fatal]: Add rubocop to your Gemfile"; exit 1; }
  19.  
  20. # Find all files that have been changed in comparison to master branch
  21. FILES="$(git diff master --name-only)"
  22.  
  23. echo "${green}[Ruby Style][Info]: Checking Ruby Style${NC}"
  24.  
  25. if [ -n "$FILES" ]
  26. then
  27. echo "${green}[Ruby Style][Info]: Checking Files:\n${FILES}${NC}"
  28.  
  29. if [ ! -f '.rubocop.yml' ]; then
  30. echo "${yellow}[Ruby Style][Warning]: No .rubocop.yml config file.${NC}"
  31. fi
  32.  
  33. # Run rubocop on the files
  34. rubocop ${FILES}
  35.  
  36. if [ $? -ne 0 ]; then
  37. echo "${red}[Ruby Style][Error]: Fix the issues and commit again${NC}"
  38. exit 1
  39. fi
  40. else
  41. echo "${green}[Ruby Style][Info]: No files to check${NC}"
  42. fi
  43.  
  44. exit 0
Add Comment
Please, Sign In to add comment