Skip to content

Instantly share code, notes, and snippets.

@dannysauer
Created May 6, 2022 17:13
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 dannysauer/bfd364c1bb19fcc1b9769e5aba6f104e to your computer and use it in GitHub Desktop.
Save dannysauer/bfd364c1bb19fcc1b9769e5aba6f104e to your computer and use it in GitHub Desktop.
quick github stats
#!/bin/bash
ORG=Kong
declare -A externals
printf "repo,user,external?\n"
for REPO in $(gh api --paginate "/orgs/$org/repos?type=public&sort=full_name&per_page=100" \
| jq -r '.[] | select( .fork == false ) | .name')
do
echo "processing $REPO" >&2
for USER in $(gh api --paginate "/repos/$org/$REPO/contributors?per_page=100" | jq -r '.[] | .login')
do
if [[ ${externals[$USER]+_} ]]
then
# alredy-chcked user
:
else
if gh api "/orgs/$org/members/$USER" > /dev/null 2>&1
then
externals[$USER]=0
else
externals[$USER]=1
fi
fi
printf "$REPO,$USER,${externals[$USER]}\n"
done
done
count=0
total=0
for c in "${!externals[@]}"
do
(( total++ ))
(( count+= ${externals[$c]} ))
done
printf "$count external contributors out of $total total\n" >&2

Check out all the repositories, given a list of repositories in the parent directory. The NR!=1 thing in awk skips the first line, and the $0=$1 assigns the first field to the whole line ($0 is what's printed with no other action). I think the rest is pretty self-explanatory?

./contributors.sh > contributors.csv
awk -F, 'NR != 1 && $0=$1' contributors.csv | sort -u > repolist
mkdir repo
cd repo
for repo in $(<../repolist); do git clone https://github.com/Kong/$repo; done

Get all the non-Kong / non-mashape contributors:

for D in *; do git -C $D log --pretty="%an <%ae>%n%cn <%ce>"; done | sort -u | grep -v -e @mashape.com -e @konghq.com > ../repousers.txt

All contributors, with counts:

for D in *; do echo $D; git -C $D shortlog -sne --all; done | tee ../contributors.txt
@dannysauer
Copy link
Author

Note that the github group membership thing only knows about current members; it does not remember contributors' prior affiliation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment