Created
June 28, 2023 17:09
-
-
Save mankins/b9f25727c690cc89f5b60b4da881b731 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 | |
# get repo from command line | |
repo=$1 | |
# parentWeight, default to 1 | |
parentWeighting=${2:-1} | |
# if no repo, exit | |
if [ -z "$repo" ]; then | |
echo "No repo specified" | |
exit 1 | |
fi | |
# clone repo into a temporary directory | |
tmp=$(mktemp -d) | |
cd $tmp | |
git clone --filter=tree:0 $repo . | |
# Get the list of authors and commit counts | |
authors=$(git log --format='%ae' | sort | uniq -c | sort -nr) | |
# Get the total weight | |
total=$(echo "$authors" | awk '{ sum += $1 } END { print sum }') | |
# Generate a traceId, a uuid, for this kudos transaction | |
traceId=$(uuidgen | xxd -r -p | base64 | sed 's/+/-/g; s/\//_/g; s/=//g') | |
# Loop through each author and get their GitHub username | |
while read -r line; do | |
count=$(echo "$line" | awk '{ print $1 }') | |
email=$(echo "$line" | awk '{ print $2 }') | |
# username=$(curl -s "https://api.github.com/search/users?q=$email+in:email" | jq -r '.items[0].login') | |
# Calculate the weight for this author | |
weight=$(echo "scale=5; $count / $total * $parentWeighting" | bc) | |
weight=$(printf "%.5f" $weight) | |
# Generate a unique ID for this kudos | |
id=$(uuidgen | xxd -r -p | base64 | sed 's/+/-/g; s/\//_/g; s/=//g') | |
# Get the current timestamp in UTC | |
ts=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
# Output the kudos information in JSON format | |
# {"identifier":"did:kudos:email:$email","id":"XR8C4DfXjRTWykQF3xMtF2","ts":"2023-06-28T16:08:04Z","weight":1,"traceId":"XR7whJG3zbH5jFbdJpJjv8"} | |
echo "{\"identifier\":\"did:kudos:email:$email\",\"id\":\"$id\",\"ts\":\"$ts\",\"weight\":$weight,\"traceId\":\"$traceId\"}" | |
done <<< "$authors" | |
# remove temporary directory | |
rm -rf $tmp |
% ./download-repo-get-weights.sh https://github.com/gtanner/qrcode-terminal.git
Cloning into '.'...
remote: Enumerating objects: 52, done.
remote: Total 52 (delta 0), reused 0 (delta 0), pack-reused 52
Receiving objects: 100% (52/52), 9.55 KiB | 9.55 MiB/s, done.
Resolving deltas: 100% (2/2), done.
remote: Enumerating objects: 7, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 7 (delta 0), reused 0 (delta 0), pack-reused 6
Receiving objects: 100% (7/7), 1.01 KiB | 1.01 MiB/s, done.
remote: Enumerating objects: 22, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 22 (delta 0), reused 0 (delta 0), pack-reused 14
Receiving objects: 100% (22/22), 50.97 KiB | 8.49 MiB/s, done.
{"identifier":"did:kudos:email:michael@michaelbrooks.ca","id":"b-LpWUvmSZaxNIIkt-IxHA","ts":"2023-06-29T05:53:28Z","weight":0.53846,"traceId":"nuHTdSBXTgex61Dct13icg"}
{"identifier":"did:kudos:email:gtanner@gmail.com","id":"pYr0Z-YqQgSjWdm8XYfbtA","ts":"2023-06-29T05:53:28Z","weight":0.36538,"traceId":"nuHTdSBXTgex61Dct13icg"}
{"identifier":"did:kudos:email:spiro@mobify.com","id":"9XPOtl1iSJOwVV-Auag6Iw","ts":"2023-06-29T05:53:28Z","weight":0.03846,"traceId":"nuHTdSBXTgex61Dct13icg"}
{"identifier":"did:kudos:email:konrad.blum@gmail.com","id":"-PXoe1uUSI2xCNIL2YVXYw","ts":"2023-06-29T05:53:28Z","weight":0.01923,"traceId":"nuHTdSBXTgex61Dct13icg"}
{"identifier":"did:kudos:email:kelvingu616@gmail.com","id":"m3gLV1EtQDCMdWLkImrTIQ","ts":"2023-06-29T05:53:28Z","weight":0.01923,"traceId":"nuHTdSBXTgex61Dct13icg"}
{"identifier":"did:kudos:email:frost@ceri.se","id":"_VJQZy4ISLyTqT5J9q6p9Q","ts":"2023-06-29T05:53:28Z","weight":0.01923,"traceId":"nuHTdSBXTgex61Dct13icg"}
%
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This one is similar to https://gist.github.com/mankins/042d58004078e716b4fec9acfac52bb8 but it takes a repo as an argument:
And optionally a weighting multiplier:
(which would produce weights half as strong)