Skip to content

Instantly share code, notes, and snippets.

@dctucker
Created October 13, 2023 21:50
Show Gist options
  • Save dctucker/af2d79a0ea4b837eae9b91fbb3aaeada to your computer and use it in GitHub Desktop.
Save dctucker/af2d79a0ea4b837eae9b91fbb3aaeada to your computer and use it in GitHub Desktop.
#!/bin/bash
declare -A object_counts=( [spokes_network]=0 [spokes_gist]=0 [pages]=0 [storage]=0 )
assoc2json() {
declare -n dict=$1
for key in "${!dict[@]}"; do
printf '%s\0%s\0' "$key" "${dict[$key]}"
done |
jq -Rs '
split("\u0000")
| . as $a
| reduce range(0; length/2) as $i
({}; . + {($a[2*$i]): ($a[2*$i + 1]|fromjson? // .)})'
}
emit_evacuation() {
jq -n -c \
--arg st "$(assoc2json object_counts)" \
--arg et "$SECONDS" \
'{
"stage": "Evacuating GitHub data",
"services": $st | fromjson,
"elapsed_time": $et | tonumber,
}'
}
emit_evacuation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment