Last active
May 2, 2020 00:09
-
-
Save mathew-fleisch/9863bc596cf18d01c29c54c5e98b6263 to your computer and use it in GitHub Desktop.
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 | |
rm -rf tmp | |
mkdir -p tmp | |
if [ -z "$1" ]; then | |
echo "Missing org name" | |
exit 1 | |
fi | |
if [ -z "$GIT_TOKEN" ]; then | |
echo "Missing git token" | |
exit 1 | |
fi | |
ORG="$1" | |
OFFSET=$(date '+%s' --date="-3 month") | |
PAGE=1 | |
REPOS="" | |
NAMES="" | |
echo "Get repo urls" | |
while [ true ]; do | |
RAW_RESPONSE=$(curl -s -H "Accept: application/vnd.github.everest-preview+json" \ | |
-H "Authorization: token ${GIT_TOKEN}" \ | |
--request GET \ | |
https://api.github.com/orgs/$ORG/repos?sort=full_name\&per_page=100\&page=$PAGE) | |
# echo "$RAW_RESPONSE" | |
RESPONSE=$(echo "$RAW_RESPONSE" | jq -r '.[].ssh_url') | |
NAME=$(echo "$RAW_RESPONSE" | jq -r '.[].name') | |
NUM_REPOS=$(echo "$RESPONSE" | wc -l) | |
# echo "$RESPONSE" | |
REPOS="$REPOS | |
$RESPONSE" | |
NAMES="$NAMES | |
$NAME" | |
if [ "$NUM_REPOS" -lt 100 ]; then | |
# echo "must be the last page..." | |
break | |
fi | |
PAGE=$((PAGE + 1)) | |
done | |
# NAMES="agent secure-backend backend sds-frontend sysdig-inspect" | |
for repo in $(echo "$NAMES"); do | |
# /repos/:owner/:repo/stats/contributors | |
RAW_RESPONSE=$(curl -s -H "Accept: application/vnd.github.everest-preview+json" \ | |
-H "Authorization: token ${GIT_TOKEN}" \ | |
--request GET \ | |
https://api.github.com/repos/$ORG/$repo/stats/contributors) | |
echo "$repo:" | |
echo "curl -s -H \"Accept: application/vnd.github.everest-preview+json\" -H \"Authorization: token ${GIT_TOKEN}\" --request GET https://api.github.com/repos/$ORG/$repo/stats/contributors" | |
# sleep 1 | |
for user in $(echo "$RAW_RESPONSE" | jq -c '.[]'); do | |
user_github=$(echo $user | jq -r '.author.login') | |
echo "User: $user_github" | |
# echo "$user" | |
RECENT_CONTRIBUTIONS=0 | |
for week in $(echo $user | jq -c '.weeks[]'); do | |
WEEK_OF_COMMIT=$(echo $week | jq '.w') | |
NUMBER_OF_COMMITS=$(echo $week | jq '.c') | |
if [ $WEEK_OF_COMMIT -gt $OFFSET ] && [ $NUMBER_OF_COMMITS -gt 0 ]; then | |
echo "$user_github,$WEEK_OF_COMMIT,$NUMBER_OF_COMMITS" | |
RECENT_CONTRIBUTIONS=$((RECENT_CONTRIBUTIONS + NUMBER_OF_COMMITS)) | |
fi | |
done | |
if [ $RECENT_CONTRIBUTIONS -gt 0 ]; then | |
echo "$user_github,${OFFSET}+,$RECENT_CONTRIBUTIONS" >> "tmp/$repo" | |
fi | |
echo "Number of contributions (since $OFFSET): $RECENT_CONTRIBUTIONS" | |
done | |
# echo "$RAW_RESPONSE" | |
# echo "$RESPONSE" | |
echo "--------------------------------------" | |
# exit 0 | |
done | |
# Get unique contributors: | |
# cat tmp/* | sort | awk -F ',' '{print $1}' | uniq | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment