Advertisement
Guest User

Untitled

a guest
Dec 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. _table="system_branch_overview"
  2. _deleteQuery="Delete from "$_table
  3. mysql --user="dashboard" --password="dashboard" --host="data.cgn" "cc-statistics" --protocol=TCP -e "$_deleteQuery"
  4. #------------navigate----------------------
  5. for d in ./*/
  6. do
  7. cd "$d"
  8. _gitDir="$(git rev-parse --is-inside-work-tree 2>/dev/null)"
  9. if [ "$_gitDir" == "true" ]
  10. then
  11. _system="${d:2}"
  12. _system="${_system::-1}"
  13. #-------------branch------------------------
  14. git branch > tmp_checked_branch.file
  15. _file='tmp_checked_branch.file'
  16. _re="*"
  17. while IFS='' read -r p || [ -n "$p" ]; do
  18. if [ "${p:0:1}" == "$_re" ]
  19. then
  20. _checked_branch="${p:2}"
  21. fi
  22. done < "$_file"
  23. rm "$_file"
  24. #-------------commit hash--------------------
  25. git show -s > tmp_checked_commit.file
  26. _file='tmp_checked_commit.file'
  27. _commitHash=$(head -1 "$_file")
  28. _commitHash="${_commitHash:7}"
  29. #-------------commit date $ message----------
  30. headtail2=$(head -2 "$_file" | tail +2)
  31. if [[ "$_headtail2" =~ "Merge"* ]]
  32. then
  33. _commitDate=$(head -4 "$_file" | tail +4)
  34. _commitMessage=$(cat "$_file" | tail +6)
  35. elif [[ "_$headtail2" =~ "Author"* ]]
  36. then
  37. _commitDate=$(head -3 "$_file" | tail +3)
  38. _commitMessage=$(cat "$_file" | tail +5)
  39. fi
  40. #remove "Date: "
  41. _commitDate="${_commitDate:8}"
  42. #format date for sql insert
  43. _commitDate="${_commitDate:4:20}"
  44. _cDate="${_commitDate: -1}"
  45. echo "$_cDate"
  46. if [[ !"$_cDate" =~ [0-9]+$ ]]
  47. then
  48. _commitDate="${_commitDate:19}"
  49. fi
  50. #echo "$_commitDate"
  51. #remove 4 leading whitespaces
  52. _commitMessage="${_commitMessage:4}"
  53. rm "$_file"
  54. #----------------sql insert-------------------
  55. _table="system_branch_overview"
  56. _toDate="STR_TO_DATE('$_commitDate','%M %d %h:%i:%s %Y')"
  57. _insertQuery="INSERT INTO "$_table" VALUES ('"$_commitHash"','"$_system"','"$_checked_branch"','"$_commitMessage"',"$_toDate")"
  58. echo "$_insertQuery"
  59. mysql --user="dashboard" --password="dashboard" --host="data.cgn" "cc-statistics" --protocol=TCP -e "$_insertQuery"
  60. fi
  61. cd ..
  62. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement