Skip to content

Instantly share code, notes, and snippets.

@zlatko-minev
Created December 1, 2020 02:20
Show Gist options
  • Select an option

  • Save zlatko-minev/105a688fece80c75f2b73e4bb4d05b11 to your computer and use it in GitHub Desktop.

Select an option

Save zlatko-minev/105a688fece80c75f2b73e4bb4d05b11 to your computer and use it in GitHub Desktop.
# Zlatko Minev 2020
# Batch add users from a list to a repository on GitHub.com using their RestV3 API
# from file `names.txt` each new line has a new user id or url
# Also log result to screen and file.
# To test your connection first, try to get user info:
# curl -i -u "${GH_USER}:${PASSWORD}" "https://api.github.com/users/zlatko-minev"
# and see if you get a valid response.
GH_USER="my-user-name"
PASSWORD="USE_OAUTH_OR_TOKEN"
repo="owner/repo-name" # such as pandas-dev/pandas
printf "\n\n\nStarting\n\n" 2>&1 | tee -a _log.txt
while read line; do
# trim all white spaces
line="$(echo -e "${line}" | tr -d '[:space:]')"
# trim github prefix
suffix=""
prefix="https:\/\/github.com\/"
line="$(echo "$line" | sed -e "s/^$prefix//" -e "s/$suffix$//")"
# trim github prefix
prefix="github.com\/"
line="$(echo "$line" | sed -e "s/^$prefix//" -e "s/$suffix$//")"
printf "Adding \e[42m$line\e[0m\n" 2>&1 | tee -a _log.txt
curl -i -u "${GH_USER}:${PASSWORD}" -X "PUT" "https://api.github.com/repos/$repo/collaborators/$line" 2>&1 | tee -a _log.txt
done <names.txt
@zlatko-minev
Copy link
Copy Markdown
Author

Tested and ran on Nov. 30, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment