Skip to content

Instantly share code, notes, and snippets.

@ynezz
Created April 1, 2024 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ynezz/e6f4219b7be20fa0f44b0f3832c26d59 to your computer and use it in GitHub Desktop.
Save ynezz/e6f4219b7be20fa0f44b0f3832c26d59 to your computer and use it in GitHub Desktop.
git-signed-commits-stats.sh
#!/bin/bash
since="${1:-1 month ago}"
good_signatures=0
unsigned_commits=0
bad_signatures=0
unknown_signatures=0
# Loop through each commit from the last 2 years
while read -r commit_hash signature_status; do
case $signature_status in
B) ((bad_signatures++)) ;;
N) ((unsigned_commits++)) ;;
E) ((unknown_signatures++)) ;;
G|Y|X|R) ((good_signatures++)) ;;
esac
done < <(git log --since="$since" --pretty="%H %G?")
total_commits=$((good_signatures + unsigned_commits + bad_signatures + unknown_signatures))
if [ "$total_commits" -gt 0 ]; then
good_percentage=$(echo "scale=2; $good_signatures / $total_commits * 100" | bc)
unsigned_percentage=$(echo "scale=2; $unsigned_commits / $total_commits * 100" | bc)
bad_percentage=$(echo "scale=2; $bad_signatures / $total_commits * 100" | bc)
unknown_percentage=$(echo "scale=2; $unknown_signatures / $total_commits * 100" | bc)
else
echo "No commits found in the specified time range."
exit 1
fi
echo "Total commits: $total_commits (since $since)"
echo "Good signatures: $good_signatures ($good_percentage%)"
echo "Unsigned commits: $unsigned_commits ($unsigned_percentage%)"
echo "Bad signatures: $bad_signatures ($bad_percentage%)"
echo "Unknown signature status: $unknown_signatures ($unknown_percentage%)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment