Skip to content

Instantly share code, notes, and snippets.

@tariqajyusuf
Last active December 26, 2023 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tariqajyusuf/cc43ccfa7c17e4122aa4e85f2fda8b4d to your computer and use it in GitHub Desktop.
Save tariqajyusuf/cc43ccfa7c17e4122aa4e85f2fda8b4d to your computer and use it in GitHub Desktop.
Get number of GitHub contributors in the last quarter for an organization
ORG=my-org-name
# Query to get repos within an org with a definex primary language
GETREPOQUERY=$(cat <<-END
query (\$endCursor: String) {
organization(login: "Remitly") {
repositories(first: 100, after: \$endCursor) {
nodes {
name
primaryLanguage {
name
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
END
)
# Get number of processors (for linux or mac)
NUMCPUS=$(nproc || sysctl -n hw.ncpu)
echo "Getting repositories for $ORG..."
# Get all repositories with a primary language (it looks like this only includes programming languages and not things like Markdown)
gh api graphql --paginate -q '.data.organization.repositories.nodes | flatten(1).[] | select(.primaryLanguage.name) | .name' -f query="$GETREPOQUERY" > repos.txt
echo "$ORG has $( cat repos.txt| wc -l | sed 's/ //g') repositories"
# Get users that acted on this repo in the last quarter
echo "Getting quarterly contributions for $ORG repos (parellelizing with $NUMCPUS threads)"
cat repos.txt | xargs -I % -P $NUMCPUS gh api "/repos/$ORG/%/activity?time_period=quarter" -q '.[].actor.login' | sort -u > contributors.txt
# Get overlap of org users and contributors to repos
echo "$(cat contributors.txt| wc -l | sed 's/ //g') unique users contributed to $ORG this quarter. See contributors.txt for details."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment