From c1aa6e12a559257afb333168190c97611cd25887 Mon Sep 17 00:00:00 2001 From: g0t mi1k Date: Wed, 24 Nov 2021 10:14:08 +0000 Subject: [PATCH] Add shell script to generate GitHub avatars --- .bin/generate-contributors | 86 ++++++++++++++++++++++++++++++++++++++ CONTRIBUTORS.md | 2 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 .bin/generate-contributors diff --git a/.bin/generate-contributors b/.bin/generate-contributors new file mode 100755 index 0000000..8159181 --- /dev/null +++ b/.bin/generate-contributors @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# +## Requires jq +# +## Example: bash github-api-contributors-gen.sh "danielmiessler/SecLists" +# + +## https://github.com/ +githubRepo=${1:-danielmiessler/SecLists} + +## How many avatar's per row +avatar_row=5 + +## Start at the start +page=1 + +## Empty the values +login=() +avatar_url=() +url=() + +## Do until there isn't anything returned +while true; do + ## Call the API, to extract the JSON for that page + json=$( curl -s "https://api.github.com/repos/${githubRepo}/contributors?page=${page}" ) + + ## Check to see if its empty or not - if it is, exit the loop + [[ -z "$( echo ${json} | jq -r '.[]' )" ]] \ + && break + + ## Loop over all three values, save to an array (dirty - as multiple loops hardcoded...) + for x in $( echo ${json} | jq -r ".[].login" ); do + login+=($x) + done + + for x in $( echo ${json} | jq -r ".[].avatar_url" ); do + avatar_url+=($x) + done + + for x in $( echo ${json} | jq -r ".[].url" ); do + url+=($x) + done + + ## Check to make sure all arrays are the same length (dirty - but works...) + if [ "${#login[@]}" -ne "${#avatar_url[@]}" ]; then + echo "[-] Issues with login & avatar_url" + exit 1 + elif [ "${#login[@]}" -ne "${#url[@]}" ]; then + echo "[-] Issues with login & url" + exit 1 + fi + + ## Increase the page count + (( page ++)) +done + + +## Make markdown headers +for x in " " "---"; do + echo -n "|" + for y in $( seq 1 "${avatar_row}" ); do + echo -n "${x}|" + done + echo +done + + +## Counter for avatar_row +i=1 +## For every value in the arrays above, do the following +for x in $( seq 0 "${#login[@]}" ); do + ## As array starts at 0, length starts at 1, there will be one extra - skip the end! + [ ${x} -eq ${#login[@]} ] \ + && break + + echo -n "
[${login[${x}]}](${url[${x}]}) | " + + ## Every x rows, do put onto a new line + [ $i -ge ${avatar_row} ] \ + && i=0 \ + && echo + + ## Increase the row count + (( i ++)) +done +echo diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ffcbad4..a598d1c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -39,7 +39,7 @@ This project stays great because of care and love from the [community](https://g - - - - + | | | | | | |---|---|---|---|---|
[g0tmi1k](https://api.github.com/users/g0tmi1k) |
[danielmiessler](https://api.github.com/users/danielmiessler) |
[jhaddix](https://api.github.com/users/jhaddix) |
[righettod](https://api.github.com/users/righettod) |
[toxydose](https://api.github.com/users/toxydose) |