Accept all invitations to collaborate on Github
This file contains 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
#!/bin/bash | |
# must install JQ | |
# https://stedolan.github.io/jq/download/ | |
# on OSX brew install jq | |
# must set Github Personal Access Token with full repo access only | |
### Set named arguments -t | |
while getopts ":t:" opt; do | |
case $opt in | |
t) TOKEN="$OPTARG" | |
;; | |
\?) echo "Invalid option -$OPTARG" >&2 | |
;; | |
esac | |
done | |
### Validate inputs | |
if [ -z ${TOKEN+x} ]; then | |
echo " Github Personal Access Token (-t) must be set" | |
exit 1 | |
fi | |
# get list of invites (to trouble shoot add -i to show headers) | |
INVITES=$(curl "https://api.github.com/user/repository_invitations?access_token=${TOKEN}") | |
# array to contain IDs | |
INVITE_ID_LIST=() | |
# Loop through JSON response, remove spaces and new lines as well as removing quotes (-r) | |
for INVITE in $(echo "${INVITES}" | jq -r '.[] | @base64') | |
do | |
_jq() { | |
echo ${INVITE} | base64 --decode | jq -r ${1} | |
} | |
echo 'Invite ID', $(_jq '.id') | |
INVITE_ID_LIST+=($(_jq '.id')) | |
done | |
# loop through invite IDs and accept them | |
for ID in ${INVITE_ID_ARRAY[@]} | |
do | |
curl -X PATCH "https://api.github.com/user/repository_invitations/${ID}?access_token=${TOKEN}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment