Created
December 31, 2024 10:03
-
-
Save arturu/63529aa671ceb7ae1c63651e8d24b803 to your computer and use it in GitHub Desktop.
This script exports the commit history of multiple repositories into a single output sorted by date. The output formats are: csv, gource and mp4.
This file contains hidden or 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 | |
################################################################################ | |
# | |
# This script exports the commit history of multiple repositories | |
# into a single output sorted by date. | |
# The output formats are: csv, gource and mp4. | |
# | |
# Author: Pietro Arturo Panetta | |
# Site: https://github.com/arturu | |
# Copyright: @arturu 2024 | |
# License: AGPL-3.0-only | |
# | |
################################################################################ | |
# Main path containing the repositories | |
ROOT_PATH="/absolute/path/to/repositories" | |
# Outpath | |
OUTPUT_PATH="/absolute/path/to/script_output_folder" | |
# Output file for the CSV | |
CSV_FILE="$OUTPUT_PATH/cronologia_commits.csv" | |
# Output file for Gource logs | |
COMBINED_LOG="$OUTPUT_PATH/gource_combined.txt" | |
# Create the output directory if it doesn't exist | |
mkdir -p "$OUTPUT_PATH" | |
# Navigate to the main directory | |
cd "$ROOT_PATH" || exit | |
# Ask the user if they want to perform git pull | |
read -rp "Do you want to perform git pull for all repositories? (y/n): " do_pull | |
# Ask the user what to do with Gource | |
echo -e "\nWhat would you like to do with Gource after the script finishes?" | |
echo "1) Exit" | |
echo "2) Launch Gource" | |
echo "3) Export a video with Gource" | |
read -rp "Select an option (1/2/3): " gource_action | |
# Clear existing output files without deleting them | |
> "$CSV_FILE" | |
> "$COMBINED_LOG" | |
# Iterate through each directory | |
for dir in */; do | |
if [ -d "$dir/.git" ]; then | |
REPO_NAME=${dir%/} # Repository name | |
echo "Processing $REPO_NAME..." | |
cd "$dir" || continue | |
# Perform git pull if requested | |
if [[ "$do_pull" == "y" ]]; then | |
echo "Performing git pull for $REPO_NAME..." | |
git pull --quiet | |
fi | |
# Extract commits for the CSV | |
git log --pretty=format:"$REPO_NAME,%h,%ad,%an,\"%s\"" --date=iso >> "$CSV_FILE" | |
echo "" >> "$CSV_FILE" | |
# Generate custom log for Gource | |
echo "Generating log for Gource..." | |
gource --output-custom-log "$OUTPUT_PATH/gource_${REPO_NAME}.txt" . | |
# Add the repository prefix to Gource log | |
sed -i -r "s#(.+)\|#\1|/$REPO_NAME#" "$OUTPUT_PATH/gource_${REPO_NAME}.txt" | |
# Return to the main directory | |
cd .. | |
fi | |
done | |
# Merge and sort Gource logs | |
echo "Merging and sorting Gource logs..." | |
cat "$OUTPUT_PATH"/gource_*.txt | sort -n > "$COMBINED_LOG" | |
# Sort commits chronologically in the CSV file | |
sort -t ',' -k3,3 "$CSV_FILE" -o "$CSV_FILE" | |
echo "Commit log exported to $CSV_FILE." | |
echo "Combined log for Gource generated in $COMBINED_LOG." | |
# Final actions with Gource | |
case $gource_action in | |
1) | |
echo "Exiting the script. Goodbye!" | |
exit 0 | |
;; | |
2) | |
# Check if Gource is installed | |
if ! command -v gource &> /dev/null; then | |
echo "Error: Gource is not installed. Please install it before using this option." | |
exit 1 | |
fi | |
echo "Launching Gource..." | |
gource --seconds-per-day 1 "$COMBINED_LOG" | |
exit 0 | |
;; | |
3) | |
# Check if FFmpeg is installed | |
if ! command -v ffmpeg &> /dev/null; then | |
echo "Error: FFmpeg is not installed. Please install it before exporting a video." | |
exit 1 | |
fi | |
echo "Exporting video with Gource..." | |
gource --output-ppm-stream - "$COMBINED_LOG" | \ | |
ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -crf 1 -threads 0 "$OUTPUT_PATH/gource_video.mp4" | |
echo "Video exported to $OUTPUT_PATH/gource_video.mp4." | |
exit 0 | |
;; | |
*) | |
echo "Invalid choice. Exiting." | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment