forked from intentionally-left-nil/github-pair-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpair_with.sh
More file actions
executable file
·57 lines (50 loc) · 1.6 KB
/
pair_with.sh
File metadata and controls
executable file
·57 lines (50 loc) · 1.6 KB
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
# These functions set and unset environment variables
# As such, they need to be compatible with bash and zsh
# so they can run in the current context, and not as a child process
function pair_with()
{
if [ "$#" -eq 0 ]; then
work_solo
else
pairing_with $1
if [ "$?" -eq 0 ]; then
echo "Now pairing with $GIT_PAIR_NAME <$GIT_PAIR_EMAIL>"
fi
fi
}
function work_solo()
{
unset GIT_PAIR_USERNAME
unset GIT_PAIR_NAME
unset GIT_PAIR_EMAIL
echo "Now working solo"
}
function pairing_with()
{
local username=$1
local profile=`curl -H "Accept: application/json" -s GET "https://api.github.com/users/$username"`
local name=`echo $profile | jq -r ".name"`
local email=`echo $profile | jq -r ".email"`
if [[ "$name" == "null" ]]; then
local profilemessage=`echo $profile | jq -r ".message"`
if [[ "$profilemessage" == "Not Found" ]]; then
echo "$username is not a valid github username"
return 1
fi
if [[ "$profilemessage" = *"API rate limit exceeded"* ]]; then
echo "The Github API is currently rate limited"
echo "Please manually export GIT_PAIR_NAME and GIT_PAIR_EMAIL"
return 2
fi
fi
if [[ "$email" == "null" ]]; then
local events=`curl -H "Accept: application/json" -s GET "https://api.github.com/users/$username/events/public"`
email=$(echo $events | jq -r ".[].payload?.commits?[]?.author? | select(.name == \"$name\") | .email" | head -n 1)
if [[ -z "$EMAIL" ]]; then
email="$1@users.noreply.github.com"
fi
fi
export GIT_PAIR_USERNAME="$usermame"
export GIT_PAIR_NAME="$name"
export GIT_PAIR_EMAIL="$email"
}