|
| 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 |
0 commit comments