Last active
November 26, 2024 14:13
-
-
Save morkin1792/2ac94289d6115e86d1f156e612d22bb4 to your computer and use it in GitHub Desktop.
This script searches for personal emails by checking the repositories of a given GitHub user.
This file contains hidden or 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
function findGithubEmails() { | |
username="$1" | |
remove_fork="${2:-N}" | |
if [ -z $ZSH_VERSION ]; then | |
printf "$(hostname): Oops, this script requires zsh! \n$(whoami): Why?\n$(hostname): Well... there are some problems, one of them is https://stackoverflow.com/q/59289355 \n$(whoami): You convinced me, how can I install zsh? \n$(hostname): https://itsfoss.com/zsh-ubuntu/ or https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH\n" | |
return | |
fi | |
function checkRateLimit() { | |
if $(printf "%s" "$1" | grep -q 'rate limit'); then | |
printf "[*] GitHub API has reached the rate limit, you can wait a few minutes, change your IP address or modify this code to use an API token.\n" >&2 | |
return 2 | |
fi | |
} | |
message=$(curl -s "https://api.github.com/users/$username/repos?page=1&per_page=100") | |
repos=( $(printf "%s" "$message" | jq -r '.[] | .name' 2>/dev/null || exit 2) ) | |
if [ $? = 2 ]; then | |
checkRateLimit "$message" | |
if [ $? != 2 ]; then | |
printf "[-] Something is wrong, the API is returning:\n" | |
printf "$message" | jq | |
fi | |
return | |
fi | |
if [ "$remove_fork" != "N" ] && [ "$remove_fork" != "n" ] && [ "$remove_fork" != "0" ];then | |
repos=( $(printf "%s" "$message" | jq -r '.[] | select (.fork != true) | .name') ) | |
printf "[*] Filtering forks\n" | |
fi | |
printf "[*] Found ${#repos[@]} public repositories\n\n" | |
allEmails=() | |
for repo in "${repos[@]}"; do | |
printf "https://github.com/$username/$repo\n" | |
currentEmails=() | |
function findEmails() { | |
commits="$(curl -s https://api.github.com/repos/$username/$repo/commits)" | |
checkRateLimit "$commits" | |
[ $? = 2 ] && return | |
set -o pipefail | |
printf "%s" "$commits" | jq '.[] | .commit' 2> /dev/null | jq '.author,.committer' | jq -r '.name + ":" + .email' | sort -u | |
} | |
function appendArray() { | |
while read; do currentEmails+=("$REPLY"); done | |
} | |
set -o pipefail | |
(findEmails || ([ $? = 2 ] && break) ) | appendArray | |
printf '%s\n' "${currentEmails[@]}" | sed 's/^/\t/g' | |
allEmails+=( $currentEmails ) | |
done | |
printf '\n\n[!] Final results:\n' | |
printf '%s\n' "${allEmails[@]}" | sort -u | grep -Ev 'users.noreply.github.com|[email protected]' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment