-
Notifications
You must be signed in to change notification settings - Fork 184
/
get-email.sh
executable file
·62 lines (55 loc) · 2.02 KB
/
get-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
#!/usr/bin/env bash
# Given a tag and a draft, attempt to work out who is responsible for the submission.
#
# This tries several things, starting from a simple UPLOAD_EMAIL environment variable.
# Then it looks at the email of the person that tagged the commit, if that is set.
# Then it starts looking for who made the commit or who authored the commit.
# For each of these, GitHub could use a <user>@users.noreply.github.com address.
# In which case, this attempts to use the GitHub API to get their email.
# Finally, this picks the first listed author email address from the draft.
tried=()
emailok() {
tried+=("$1")
if [ -n "$2" -a "$2" != "[email protected]" ]; then
echo "$2"
exit 0
fi
}
# Exit on errors,
set -e
# ... but don't print anything; we're using tokens.
set +x
emailok "\$UPLOAD_EMAIL environment variable" "$UPLOAD_EMAIL"
tag="$1"
draft="$2"
for k in taggeremail committeremail authoremail; do
tagger="$(git tag --list --format '%('"$k"')' "$tag" | sed -e 's/^<//;s/>$//')"
ghuser="${tagger%@users.noreply.github.com}"
if [ "$ghuser" = "$tagger" ]; then
emailok "git $k" "$tagger"
elif [ -n "$GITHUB_API_TOKEN" ]; then
script="import json,sys
e=json.load(sys.stdin).get('email')
if isinstance(e, str): print(e)"
userjson="$(curl -SsLf \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_API_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/users/$ghuser" 2>/dev/null)"
apiok=$?
emailok "github API for $k ($ghuser)" \
"$([ "$apiok" -eq 0 ] && echo "$userjson" | python -c "$script" 2>/dev/null)"
fi
done
if [ -n "$draft" ]; then
emailok "draft author" "$(xmllint --xpath '/rfc/front/author[1]/address/email/text()' "$draft" 2>/dev/null)"
fi
# Give up
{
echo "Unable to find email to use for submission."
echo "Tried:"
for t in "${tried[@]}"; do
echo " $t"
done
} 1>&2
exit 1