Last active
April 26, 2025 17:39
-
-
Save codingchili/506481e587ec2e36221b43ff0e416843 to your computer and use it in GitHub Desktop.
lists commits with files changed for matching emails
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 | |
# Usage: ./find_commits.sh inputfile.txt filter_domain | |
FILTER_DOMAIN="$1" | |
AUTHORS_FILE="authors.txt" | |
ATTRIBUTION_FILE="attribution.txt" | |
# Colors for terminal output | |
RESET='\033[0m' | |
GREEN='\033[32m' | |
YELLOW='\033[33m' | |
RED='\033[31m' | |
BLUE='\033[34m' | |
MAGENTA='\033[35m' | |
CYAN='\033[36m' | |
# Function to print colored text | |
print_color() { | |
echo -e "${1}${2}${RESET}" | |
} | |
# Spinner function | |
spin() { | |
local -a sp=("⠋" "⠙" "⠸" "⠴" "⠦" "⠇") | |
local i=0 | |
while kill -0 "$1" 2>/dev/null; do | |
printf "\r${YELLOW}${sp[i]} Working...${RESET}" | |
i=$(( (i + 1) % 6 )) | |
sleep 0.1 | |
done | |
printf "\r${GREEN}✔️ Done extracting commits!${RESET}\n" | |
} | |
# Usage check | |
if [[ -z "$FILTER_DOMAIN" ]]; then | |
print_color "$RED" "❌ Usage: $0 <filter_domain>" | |
exit 1 | |
fi | |
print_color "$CYAN" "🏷️ Checking current Git tag.." | |
print_color "$CYAN" "📚 Generating authors from $(git describe --tags --exact-match 2>/dev/null || echo 'unknown tag')" | |
# Run git log in background | |
(git log --pretty=format:"%an <%ae>" | sort | uniq -c | sort -nr > "$AUTHORS_FILE") & | |
GIT_PID=$! | |
spin $GIT_PID | |
# Filter authors | |
TOTAL_AUTHORS=$(wc -l < "$AUTHORS_FILE") | |
print_color "$YELLOW" "🔍 Found $TOTAL_AUTHORS authors in branch .." | |
EMAILS=$(grep -a -oP '<\K[^>]+(?=>)' "$AUTHORS_FILE" | grep "$FILTER_DOMAIN" | uniq) | |
# Check if any emails found | |
if [[ -z "$EMAILS" ]]; then | |
print_color "$RED" "⚠️ No matching emails found for domain '$FILTER_DOMAIN'" | |
exit 1 | |
fi | |
# Recreate attribution file | |
touch $ATTRIBUTION_FILE | |
rm -f "$ATTRIBUTION_FILE" | |
# Process each email | |
COUNT=0 | |
TOTAL=$(echo "$EMAILS" | wc -l) | |
print_color "$BLUE" "📨 Found $TOTAL email(s) matching '$FILTER_DOMAIN'." | |
for email in $EMAILS; do | |
COUNT=$((COUNT + 1)) | |
print_color "$MAGENTA" "[$COUNT/$TOTAL] 📧 $email" | |
# shellcheck disable=SC2091 | |
$(git log --author="$email" --pretty=format:"-- %h %an %s" --name-only | awk ' | |
/^-- / { | |
print " [commit] " substr($0, 4); # Indent commit line by 4 spaces | |
next | |
} | |
NF { | |
print " [file] " $0 # Indent filenames by 8 spaces | |
} | |
' > "tmp") & | |
GIT_PID=$! | |
spin $GIT_PID | |
output=$(cat tmp) | |
if [[ -n "$output" ]]; then | |
# Display nicely | |
print_color "$GREEN" "$output" | |
echo -e "$email\n$output\n" >> "$ATTRIBUTION_FILE" | |
else | |
print_color "$RED" "⚠️ No commits found for $email." | |
fi | |
done | |
# Final success message | |
print_color "$GREEN" "🎉 Completed! Attribution file saved to: $ATTRIBUTION_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment