get_coverage_numbers 830 B

12345678910111213141516171819202122
  1. #!/usr/bin/env zsh
  2. local filename="$1"
  3. if [ -z "$filename" ]; then
  4. echo "Usage: get_coverage_totals <index.html> # from the root of an llvm-cov HTML report"
  5. return 1
  6. fi
  7. # Print the start of the JSON array
  8. echo "["
  9. first_entry=0
  10. git log --follow --pretty=format:"%H|%aI" "$filename" | while IFS='|' read -r commit_hash commit_date; do
  11. git ls-tree -r --name-only "$commit_hash" | grep -q "$filename" && index_html="$(git show $commit_hash:$filename)" || continue
  12. if [ $first_entry -eq 0 ]; then; first_entry=1; else; echo "," ;fi
  13. json_object=$( pup 'tr:last-child pre json{}' <<<"$index_html" )
  14. echo $json_object | jq -r ".[1:4] | map(.text) | {\"fn\": .[0], \"line\": .[1], \"region\": .[2], \"commit\": \"$commit_hash\", \"datetime\": \"$commit_date\"}"
  15. done
  16. # Print the end of the JSON array
  17. echo "]"