Skip to content

Instantly share code, notes, and snippets.

@narze
Last active August 1, 2022 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narze/36059068752b12ac44ece9c7930d1b36 to your computer and use it in GitHub Desktop.
Save narze/36059068752b12ac44ece9c7930d1b36 to your computer and use it in GitHub Desktop.
gh-add-user-to-repos.sh
#!/bin/bash
USER="narze"
REPOS=(
"orgname/reponame"
)
for REPO in "${REPOS[@]}"; do
echo "Adding user ${USER} to $REPO"
# https://docs.github.com/en/rest/collaborators/collaborators#add-a-repository-collaborator
gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
"/repos/$REPO/collaborators/$USER" \
-f permission='push' && echo 'Added' || echo 'Failed'
echo "\n============================================================\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment