-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-email.sh
executable file
·70 lines (58 loc) · 2.21 KB
/
github-email.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Name : github-email
# Purpose : Retrieve a GitHub user's email even though it's not public
#
#
# Based on: https://gist.github.com/sindresorhus/4512621
# Revised here: https://gist.github.com/cryptostrophe/11234026
# Now maintained in this repo.
# -----------------------------------------------------------------------------
if [[ $# -eq 0 ]]; then
printf "Usage: %s username [repository]\n" "$(basename "$0")" >&2
exit 1
fi
clear='\033[0m'
fade() {
faded='\033[30m'
printf "%b$1%b\n" "$faded" "$clear"
}
header() {
pink='\033[1;35m'
printf "\n%b$1%b\n" "$pink" "$clear"
}
user="$1"
repo="$2"
export GH_EMAIL_TOKEN="3472081c8e4a9646de001c43c05459e2e734f812"
header 'Email on GitHub'
if [ -z $GH_EMAIL_TOKEN ]; then
fade " Github requires authenticated API requests to retrieve the email. See: https://git.io/vxctz"
fade " To enable, open https://github.com/settings/tokens/new?description=github-email …"
fade " Keep the checkboxes unchecked, hit 'Generate token', copy the token, then run this in your shell:"
fade " export GH_EMAIL_TOKEN=<token>"
fade " You'll also want to add that line to your shell configuration (e.g. .bashrc)"
else
curl "https://api.github.com/users/$user?access_token=3472081c8e4a9646de001c43c05459e2e734f812" -s \
| sed -nE 's#^.*"email": "([^"]+)",.*$#\1#p'
fi
header 'Email on npm'
if hash jq 2>/dev/null; then
curl "https://registry.npmjs.org/-/user/org.couchdb.user:$user" -s | jq -r '.email'
else
echo " … skipping …. Please: brew install jq"
fi
header 'Emails from recent commits'
curl "https://api.github.com/users/$user/events" -s \
| sed -nE 's#^.*"(email)": "([^"]+)",.*$#\2#p' \
| sort -u
header 'Emails from owned-repo recent activity'
if [[ -z $repo ]]; then
# get all owned repos
repo="$(curl "https://api.github.com/users/$user/repos?type=owner&sort=updated" -s \
| sed -nE 's#^.*"name": "([^"]+)",.*$#\1#p' \
| head -n1)"
fi
curl "https://api.github.com/repos/$user/$repo/commits" -s \
| sed -nE 's#^.*"(email|name)": "([^"]+)",.*$#\2#p' \
| pr -2 -at -w 85 \
| sort -u