Created
March 15, 2024 23:45
-
-
Save ThisIsNoahEvans/97b9efd63cf884a838e4c9e98a67ca07 to your computer and use it in GitHub Desktop.
Graph of all Git commits
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 | |
# Temporary file to accumulate all commit hours from all repos | |
ALL_COMMIT_HOURS_RAW="all_commit_hours_raw.txt"> "$ALL_COMMIT_HOURS_RAW" # Clear the contents to start fresh | |
# Generate a file with all hours listed (00 to 23) | |
for i in {0..23}; do printf "%02d\n" $i; done > hours.txt | |
# Use find to recursively search for Git repositories and process each | |
find . -type d -name ".git" | while read GIT_DIR; do | |
REPO_DIR=$(dirname "$GIT_DIR") | |
echo "Processing $REPO_DIR" | |
(cd "$REPO_DIR" && git log --date=iso --pretty=format:'%ad' | awk -F" " '{print $2}' | cut -d: -f1) >> "$ALL_COMMIT_HOURS_RAW" | |
done | |
echo "Commit extraction done." | |
# Sort, count commits per hour, and ensure all hours are represented | |
sort "$ALL_COMMIT_HOURS_RAW" | uniq -c | sort -b -k2,2 > commit_hours_raw.txt | |
awk 'NR==FNR{a[$2]=$1; next} {print ($1 in a) ? a[$1] " " $1 : "0 " $1}' commit_hours_raw.txt hours.txt > commit_hours.txt | |
# Check if commit_hours.txt has data | |
if [ ! -s commit_hours.txt ]; then | |
echo "No commit hours found in any repositories. Exiting." | |
exit 1 | |
fi | |
# Plot data using gnuplot | |
gnuplot -persist <<-EOFMarker | |
set title "Commits per Hour Across All Repositories" | |
set xlabel "Hour of the Day" | |
set ylabel "Number of Commits" | |
set xtics rotate by -45 | |
set style data histograms | |
set style histogram cluster gap 1 | |
set style fill solid border -1 | |
set boxwidth 0.9 | |
set terminal png | |
set output "commit_hours_across_all_repos.png" | |
plot "commit_hours.txt" using 1:xtic(2) title 'Commits' | |
EOFMarker | |
echo "Plot saved as commit_hours_across_all_repos.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment