Skip to content

Commit c1aa6e1

Browse files
committed
Add shell script to generate GitHub avatars
1 parent 6b00e5c commit c1aa6e1

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

.bin/generate-contributors

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
#
3+
## Requires jq
4+
#
5+
## Example: bash github-api-contributors-gen.sh "danielmiessler/SecLists"
6+
#
7+
8+
## https://github.com/<value>
9+
githubRepo=${1:-danielmiessler/SecLists}
10+
11+
## How many avatar's per row
12+
avatar_row=5
13+
14+
## Start at the start
15+
page=1
16+
17+
## Empty the values
18+
login=()
19+
avatar_url=()
20+
url=()
21+
22+
## Do until there isn't anything returned
23+
while true; do
24+
## Call the API, to extract the JSON for that page
25+
json=$( curl -s "https://api.github.com/repos/${githubRepo}/contributors?page=${page}" )
26+
27+
## Check to see if its empty or not - if it is, exit the loop
28+
[[ -z "$( echo ${json} | jq -r '.[]' )" ]] \
29+
&& break
30+
31+
## Loop over all three values, save to an array (dirty - as multiple loops hardcoded...)
32+
for x in $( echo ${json} | jq -r ".[].login" ); do
33+
login+=($x)
34+
done
35+
36+
for x in $( echo ${json} | jq -r ".[].avatar_url" ); do
37+
avatar_url+=($x)
38+
done
39+
40+
for x in $( echo ${json} | jq -r ".[].url" ); do
41+
url+=($x)
42+
done
43+
44+
## Check to make sure all arrays are the same length (dirty - but works...)
45+
if [ "${#login[@]}" -ne "${#avatar_url[@]}" ]; then
46+
echo "[-] Issues with login & avatar_url"
47+
exit 1
48+
elif [ "${#login[@]}" -ne "${#url[@]}" ]; then
49+
echo "[-] Issues with login & url"
50+
exit 1
51+
fi
52+
53+
## Increase the page count
54+
(( page ++))
55+
done
56+
57+
58+
## Make markdown headers
59+
for x in " " "---"; do
60+
echo -n "|"
61+
for y in $( seq 1 "${avatar_row}" ); do
62+
echo -n "${x}|"
63+
done
64+
echo
65+
done
66+
67+
68+
## Counter for avatar_row
69+
i=1
70+
## For every value in the arrays above, do the following
71+
for x in $( seq 0 "${#login[@]}" ); do
72+
## As array starts at 0, length starts at 1, there will be one extra - skip the end!
73+
[ ${x} -eq ${#login[@]} ] \
74+
&& break
75+
76+
echo -n "<img width='50' src='${avatar_url[${x}]}'/><br />[${login[${x}]}](${url[${x}]}) | "
77+
78+
## Every x rows, do put onto a new line
79+
[ $i -ge ${avatar_row} ] \
80+
&& i=0 \
81+
&& echo
82+
83+
## Increase the row count
84+
(( i ++))
85+
done
86+
echo

CONTRIBUTORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This project stays great because of care and love from the [community](https://g
3939

4040
- - -
4141

42-
<!-- TABLE-AUTO-GENERATED ~ https://gist.github.com/g0tmi1k/ -->
42+
<!-- TABLE-AUTO-GENERATED -->
4343
| | | | | |
4444
|---|---|---|---|---|
4545
<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) |

0 commit comments

Comments
 (0)