Last active
November 14, 2024 16:42
-
-
Save gangelo/2dc7fabbd1d0a20b024f1c1de8cf1784 to your computer and use it in GitHub Desktop.
Displays git stats for a repro
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 | |
# Get the user's email from Git configuration | |
default_email=$(git config --get user.email) | |
# Get the current year | |
default_year=$(date +%Y) | |
# Prompt the user for their email, using the default from Git config | |
read -p "Enter your email (default: $default_email): " user_email | |
if [ -z "$user_email" ]; then | |
user_email=$default_email | |
fi | |
# Prompt the user for the branch to analyze, using "main" as the default | |
read -p "Enter the branch to analyze (default: main): " branch | |
if [ -z "$branch" ]; then | |
branch="main" | |
fi | |
# Prompt the user for the year to analyze, using the current year as the default | |
read -p "Enter the year to analyze (default: $default_year, leave blank for all time): " year | |
if [ -z "$year" ]; then | |
year="" | |
fi | |
# Get the number of commits in the specified year by the user, including squashed/merged commits | |
if [ -z "$year" ]; then | |
commits_by_user=$(git log --author="$user_email" --oneline | wc -l) | |
else | |
commits_by_user=$(git log --since="$year-01-01" --until="$year-12-31" --author="$user_email" --oneline | wc -l) | |
if [ $commits_by_user -eq 0 ]; then | |
echo "No commits found for the year $year in this repository." | |
fi | |
fi | |
# Get the number of merges into the specified branch by the user | |
merges_branch=$(git log --merges --author="$user_email" --oneline --first-parent $branch | wc -l) | |
# Get the number of pull requests performed by the user | |
prs_opened=$(git log --author="$user_email" --oneline --merges | grep -c "Merge pull request") | |
# Get the number of pull requests reviewed by the user | |
prs_reviewed=$(git log --committer="$user_email" --oneline --merges | grep -c "Merge pull request") | |
# Get the number of unique authors in the specified year | |
if [ -z "$year" ]; then | |
authors_last_year=$(git log --format="%ae" | sort -u | wc -l) | |
else | |
authors_last_year=$(git log --since="$year-01-01" --until="$year-12-31" --format="%ae" | sort -u | wc -l) | |
if [ $authors_last_year -eq 0 ]; then | |
echo "No authors found for the year $year in this repository." | |
fi | |
fi | |
# Get the number of tags in the repository | |
tags=$(git tag | wc -l) | |
echo "" | |
echo "Git statistics for user $user_email:" | |
echo "Metrics for the $branch branch:" | |
echo "- Commits by you: $commits_by_user" | |
echo "- Merges into the $branch branch by you: $merges_branch" | |
echo "- Pull requests opened by you: $prs_opened" | |
echo "- Pull requests reviewed by you: $prs_reviewed" | |
echo "- Unique authors in the specified year: $authors_last_year" | |
echo "- Total tags: $tags" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment