Skip to content

Instantly share code, notes, and snippets.

@skwid138
Last active June 23, 2020 15:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skwid138/b1af039714ed8d8c7908930d5bf3e783 to your computer and use it in GitHub Desktop.
Save skwid138/b1af039714ed8d8c7908930d5bf3e783 to your computer and use it in GitHub Desktop.
Accept all invitations to collaborate on Github
#!/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