Skip to content

Commit

Permalink
Add shell script to generate GitHub avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
g0tmi1k committed Nov 24, 2021
1 parent 6b00e5c commit c1aa6e1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
86 changes: 86 additions & 0 deletions .bin/generate-contributors
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
#
## Requires jq
#
## Example: bash github-api-contributors-gen.sh "danielmiessler/SecLists"
#

## https://github.com/<value>
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 "<img width='50' src='${avatar_url[${x}]}'/><br />[${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
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This project stays great because of care and love from the [community](https://g

- - -

<!-- TABLE-AUTO-GENERATED ~ https://gist.github.com/g0tmi1k/ -->
<!-- TABLE-AUTO-GENERATED -->
| | | | | |
|---|---|---|---|---|
<img width='50' src='https://avatars.githubusercontent.com/u/535942?v=4'/><br />[g0tmi1k](https://api.github.com/users/g0tmi1k) | <img width='50' src='https://avatars.githubusercontent.com/u/50654?v=4'/><br />[danielmiessler](https://api.github.com/users/danielmiessler) | <img width='50' src='https://avatars.githubusercontent.com/u/3488554?v=4'/><br />[jhaddix](https://api.github.com/users/jhaddix) | <img width='50' src='https://avatars.githubusercontent.com/u/1573775?v=4'/><br />[righettod](https://api.github.com/users/righettod) | <img width='50' src='https://avatars.githubusercontent.com/u/20900400?v=4'/><br />[toxydose](https://api.github.com/users/toxydose) |
Expand Down

0 comments on commit c1aa6e1

Please sign in to comment.