Skip to content

Instantly share code, notes, and snippets.

@blockloop
Created August 14, 2018 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blockloop/fa9b6136ac31131d758a42d03cc3954a to your computer and use it in GitHub Desktop.
Save blockloop/fa9b6136ac31131d758a42d03cc3954a to your computer and use it in GitHub Desktop.
Migrate your github repos to Gitea
#!/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