Skip to content

Instantly share code, notes, and snippets.

@danmactough
Created October 12, 2015 16:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danmactough/9289a0e8e371962216de to your computer and use it in GitHub Desktop.
Save danmactough/9289a0e8e371962216de to your computer and use it in GitHub Desktop.
I needed to add a read-only collaborator to many repositories, and doing it via the website was really tedious
#!/bin/bash
GITHUB_TOKEN=$(git config --global github.token) # I've defined an API token in my git config -- ymmv
GITHUB_USER="" # the collaborator
REPO_OWNER="" # the owner of the repos
REPOS="" # space-delimited list of repositories
PERMISSION="pull" # may be one of "admin", "push" (i.e., read/write -- default), or "pull" (i.e., read-only)
for REPO in ${REPOS} ; do
curl -X PUT -i -d '{ "permission": "'${PERMISSION}'" }' \
-H 'Accept: application/vnd.github.ironman-preview+json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
https://api.github.com/repos/${REPO_OWNER}/${REPO}/collaborators/${GITHUB_USER}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment