Skip to content

Instantly share code, notes, and snippets.

@mankins
Last active June 28, 2023 16:52
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 mankins/042d58004078e716b4fec9acfac52bb8 to your computer and use it in GitHub Desktop.
Save mankins/042d58004078e716b4fec9acfac52bb8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# parentWeighting factor will multiple weights, we will get this from the first argument, defaulting to 1
parentWeighting=${1:-1}
# 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"
@mankins
Copy link
Author

mankins commented Jun 28, 2023

You can use this to generate kudos from a git repository:

./generate-kudos-weights.sh

@mankins
Copy link
Author

mankins commented Jun 28, 2023

Note: the traceid is not using base58 like in other kudos generation, but I think this is ok? I think these just have to be unique.

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