Skip to content

Instantly share code, notes, and snippets.

@miohtama
Created November 12, 2012 23:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miohtama/4062655 to your computer and use it in GitHub Desktop.
Save miohtama/4062655 to your computer and use it in GitHub Desktop.
Migrate several SVN projects to Github using a shell script
#!/bin/zsh
#
# Install svn2git https://github.com/nirvdrum/svn2git
# Install curl: sudo apt-get install curl
#
# Create API token Github on command line before running this script
#
# curl -u 'miohtama' -d '{"scopes":["repo"],"note":"migrate.sh"}' https://api.github.com/authorizations
#
# More info https://help.github.com/articles/creating-an-oauth-token-for-command-line-use
#
# Set Github API token externally before running this script
#
# TOKEN=yourgithubtokengoeshere ./migrate.sh
#
# SVN projects to migrate
projects=("gomobile.buildout" "gomobile.convergence" "gomobile.docs" "gomobile.imageinfo" "gomobile.mobile" "gomobile.supporter" "gomobile.templates" "gomobiletheme.basic" "gomobiletheme.mobipublic" "mfabrik.webandmobile" "mobile.heurestics" "mobile.htmlprocessing" "mobile.sniffer" "mobipublic.content" "plonecommunity.app")
# Where all SVN projects are
svnbase=http://plonegomobile.googlecode.com/svn/
# Under which organization new projects are created on Github
org="plone-gomobile"
Migrate to git
for p in $projects; do
mkdir $p
cd $p
# Convert Google code SVN to Git repo
svn2git $svnbase/$p
cd ..
done
# Create Github projects, push to upstream
for p in $projects; do
# http://developer.github.com/v3/repos/#create
# http://stackoverflow.com/questions/7870680/github-v3-api-create-a-repo
# Test drive on a single liner
# TOKEN="xxxx" org="plone-gomobile" p=test ; curl -v -XPOST -H "Authorization: token $TOKEN" https://api.github.com/orgs/$org/repos -d '{"name": "'"$p"'"}'
curl -v -XPOST -H "Authorization: token $TOKEN" https://api.github.com/orgs/$org/repos -d '{"name": "'"$p"'"}'
cd $p
git remote add origin git@github.com:$org/$p.git
git push origin master
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment