Created
November 15, 2023 20:53
-
-
Save wscoble/645a677c53a08df0f0e5405b3edf4e2e to your computer and use it in GitHub Desktop.
Get the number of contributing developers over the past 90 days
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 | |
# Initialize variables | |
org_name=$1 | |
total_members=0 | |
total_contributors=0 | |
# Calculate 90 days ago in ISO8601 format | |
since_date=$(date -u -d '90 days ago' +%Y-%m-%dT%H:%M:%SZ) | |
# Fetch organization members | |
members_response=$(gh api "orgs/$org_name/members" --paginate) | |
if [[ $? -ne 0 ]]; then | |
echo "Error while fetching organization members. Exiting." | |
exit 1 | |
fi | |
# Count total organization members | |
total_members=$(echo "$members_response" | jq -r '. | length') | |
echo "total_members=$total_members" | |
# Loop through organization members to check contributions | |
for login in $(echo "$members_response" | jq -r '.[].login'); do | |
contribution_query="query(\$login: String!) { | |
user(login: \$login) { | |
contributionsCollection(from: \"$since_date\") { | |
contributionCalendar { | |
totalContributions | |
} | |
} | |
} | |
}" | |
contribution_response=$(gh api graphql -f query="$contribution_query" -f login="$login") | |
echo "queried for $login" | |
if [[ $? -ne 0 ]]; then | |
echo "Error while checking contributions for $login. Skipping." | |
continue | |
fi | |
total_contributions=$(echo "$contribution_response" | jq -r '.data.user.contributionsCollection.contributionCalendar.totalContributions') | |
if [[ "$total_contributions" -gt 0 ]]; then | |
total_contributors=$((total_contributors + 1)) | |
fi | |
done | |
# Calculate percentage of contributing members | |
percentage=0 | |
if [[ "$total_members" -gt 0 ]]; then | |
percentage=$(awk -v contributors="$total_contributors" -v members="$total_members" 'BEGIN { printf("%.2f", (contributors/members)*100) }') | |
fi | |
echo "Total organization members: $total_members" | |
echo "Total contributors in the past 90 days: $total_contributors" | |
echo "Percentage of contributors: $percentage%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment