Created
August 14, 2018 03:39
-
-
Save blockloop/fa9b6136ac31131d758a42d03cc3954a to your computer and use it in GitHub Desktop.
Migrate your github repos to Gitea
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
#!/usr/bin/env bash | |
set -o pipefail | |
# set -x | |
set -e | |
GHUSER=blockloop | |
GITEA_TOKEN=CHANGEME | |
GITEA_HOST=https://??? | |
REPOS=$(curl -SsL "https://api.github.com/users/$GHUSER/repos?per_page=20&&page=2sort=updated&direction=desc&type=owner" | \ | |
jq -r '.[] | [.name, .description, .clone_url] | join("|")') | |
while read -r repo; do | |
echo | |
echo "===========================" | |
while IFS=$'|' read name desc clone_url | |
do | |
echo "Migrating $name" | |
echo | |
[ -z "$desc" ] && desc='""' | |
echo '{ "clone_addr": "{CLONE_URL}", "description": "{DESC}", "mirror": false, "repo_name": "{NAME}", "uid": 1 }' | \ | |
sed "s|{CLONE_URL}|$clone_url|g; s|{NAME}|$name|g; s|{DESC}|$desc|g; s|{UID}|$(date +%s%N)|g; " | \ | |
tee /dev/stderr | \ | |
jq . | \ | |
curl -D /dev/stderr -H 'content-type: application/json' --data-binary @- \ | |
"$GITEA_HOST/api/v1/repos/migrate?token=$GITEA_TOKEN" | |
done < <(echo "$repo") | |
echo "===========================" | |
echo | |
done <<< "$REPOS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment