github
Table of Contents
GitHub
Helper scripts
The following scripts require two exported variables in the shell environment (not all are required but GIT_TOKEN is always required!):
Variables needed:
export GITHUB_USER=git_username export GITHUB_TOKEN=git_accesstoken
Move list of repositories to an organization
Script:
#!/bin/bash function git_repo_transfer(){ curl -vL \ -u "$2:${GITHUB_TOKEN}" \ -H "Content-Type: application/json" \ -H "Accept: application/vnd.github.v3+json" \ -X POST https://api.github.com/repos/$2/$1/transfer \ -d '{"new_owner":"'$3'"}' \ | jq . } repos=$( cat ./repos.txt) for repo in $repos; do (git_repo_transfer "$repo" "$1" "$2"); done
Update all forks (not tested!):
Script:
#!/bin/bash temp=`basename $0` TMPFILE=`mktemp /tmp/${temp}.XXXXXX` || exit 1 API_CALL="/user/repos?type=owner+fork=true" function rest_call { curl -u $GITHUB_USER:$GITHUB_TOKEN -s $1 >> $TMPFILE } last_page=`curl -u $GITHUB_USER:$GITHUB_TOKEN -s -I "https://api.github.com$API_CALL" | grep '^Link:' | sed -e 's/^Link:.*page=//g' -e 's/>.*$//g'` if [ -z "$last_page" ]; then rest_call "https://api.github.com$API_CALL" else for p in `seq 1 $last_page`; do rest_call "https://api.github.com$API_CALL?page=$p" done fi cat $TMPFILE
Source: https://gist.github.com/Skarlso/ad116ec63f646eca2cf4095acc343fa7
github.txt · Last modified: 2024-03-12 by hanez