Created
December 1, 2020 02:20
-
-
Save zlatko-minev/105a688fece80c75f2b73e4bb4d05b11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested and ran on Nov. 30, 2020