Skip to content

Instantly share code, notes, and snippets.

@marcusmueller
Created October 7, 2024 20:58
Show Gist options
  • Save marcusmueller/8b2f1d7cc5999446077cf1b706c0698a to your computer and use it in GitHub Desktop.
Save marcusmueller/8b2f1d7cc5999446077cf1b706c0698a to your computer and use it in GitHub Desktop.
Accept all invitations from specified github user
#!/bin/bash
# needs gh (off. github CLI) + jq
#
inviter="$1"
tmpdir="$(mktemp -d)"
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/user/repository_invitations \
> "${tmpdir}/all.json"
inviteids="$(< "${tmpdir}/all.json" jq '.[] | select(.inviter.login == "'"${inviter}"'") | .id')"
for iid in ${inviteids};
do
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/user/repository_invitations/${iid} \
| cat
done
rm -r "${tmpdir}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment