quickly export corpogit projects

date: 2019-10-21T19:20:00-06:00

tags: technology

gitlab

depending on your project settings, these commands may need to be repeated with `&visibility=public`, `&visibility=internal`, and `&visibility=private` added to the `/users` request. gitlab does not return the full list of projects in one request. you will need to repeat the mirror and delete commands until the list is exhausted.

git config --global credential.helper cache
git clone --mirror $some_private_repo
curl \
    -H "Authorozation: Bearer $personal_access_token" \
    -H "Accept: application/json" \
    "https://gitlab.com/api/v4/users/$username/projects?limit=100" \
    | jq .[].http_url_to_repo \
    | xargs -n1 -P4 git clone --mirror
curl \
    -H "Authorozation: Bearer $personal_access_token" \
    -H "Accept: application/json" \
    "https://gitlab.com/api/v4/users/$username/projects?limit=100" \
    | jq .[].id \
    | xargs -n1 -P4 -I{} \
    	curl \
    		-H "Authorization: Bearer $personal_access_token" \
    		-X DELETE \
    		"https://gitlab.com/api/v4/projects/{}"

github

generate personal access token with repo access:

github tokens

clone public repos

curl \
	"https://api.github.com/users/$username/repos?per_page=100" \
	| jq -r ".[].ssh_url" \
	| xargs -n 1 -P 3 git clone --mirror

clone private repos too

curl \
	-H "Authorization: token $personal_access_token" \
	'https://api.github.com/user/repos?per_page=100' \
	| jq -r ".[].ssh_url" \
	| xargs -n1 -P4 git clone --mirror

delete all repos

curl \
	"https://api.github.com/users/$username/repos?per_page=100" \
	| jq -r ".[].name" \
	| xargs -n1 -P4 -I{} \
		curl \
		-X DELETE \
		-H "Authorization: token $personal_access_token" \
		"https://api.github.com/repos/$username/{}"