Created
October 13, 2023 21:50
-
-
Save dctucker/af2d79a0ea4b837eae9b91fbb3aaeada 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 | |
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