Last active
January 1, 2024 16:02
-
-
Save Nurou/469141152e33ade3a41ca773753eef38 to your computer and use it in GitHub Desktop.
Script to get the distribution of commits between top contributors in a Git repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run git shortlog to get the contributors and their commit counts | |
git shortlog -s -n > contributors.txt | |
# Calculate total commits and average commits per contributor | |
total_commits=$(awk '{s+=$1} END {print s}' contributors.txt) | |
num_contributors=$(wc -l < contributors.txt) | |
average_commits_per_contributor=$((total_commits / num_contributors)) | |
# Get the top 5 contributors and their percentages | |
top_contributors=$(awk -v total=$total_commits '{printf "%d\t%s\t%.2f%%\n", $1, $2, ($1/total)*100}' contributors.txt | sort -nr | head -n 5) | |
# Calculate total commits for the top 5 | |
total_top_commits=$(echo "$top_contributors" | awk '{s+=$1} END {print s}') | |
# Calculate percentage for the rest of the contributors | |
percentage_rest=$(echo "scale=2; (( $total_commits - $total_top_commits ) / $total_commits ) * 100" | bc) | |
# Display the top 5 contributors | |
echo -e "Top 5 Contributors and their percentages:" | |
echo "===========================================" | |
echo "$top_contributors" | |
# Display entry for the rest of the contributors | |
echo -e "\nOther Contributors: $percentage_rest%" | |
# Clean up temporary file | |
rm contributors.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment