Created
April 7, 2015 22:33
-
-
Save nickcarenza/7338522ccd3e41a8b522 to your computer and use it in GitHub Desktop.
Migrate Bitbucket to Github
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
BITBUCKET_ORG_NAME='' | |
BITBUCKET_REPO_NAME=$1 | |
if [ -n "$2" ]; then | |
GITHUB_REPO_NAME=`echo $2 | tr '[:upper:]' '[:lower:]'` | |
else | |
GITHUB_REPO_NAME=$BITBUCKET_REPO_NAME | |
fi | |
GITHUB_ORG_NAME='' | |
GITHUB_TOKEN='...' | |
# Clone mirror the BitBucket repo | |
git clone --mirror [email protected]:${BITBUCKET_ORG_NAME}/${BITBUCKET_REPO_NAME}.git | |
if [ $? -ne 0 ]; then | |
echo "There was an error cloning the bitbucket repository" | |
exit 1 | |
fi | |
cd ${BITBUCKET_REPO_NAME}.git | |
# Set push/fetch urls on the bitbucket repo to the github url | |
# git remote set-url origin --push "[email protected]:${GITHUB_ORG_NAME}/${GITHUB_REPO_NAME}.git" | |
# git remote set-url origin "[email protected]:${GITHUB_ORG_NAME}/${GITHUB_REPO_NAME}.git" | |
READONLY_TEAM=1220658 | |
# Create repository on github | |
RESPONSE=`curl -u ${GITHUB_TOKEN}:x-oauth-basic -X POST -d '{"name": "'$GITHUB_REPO_NAME'","private":true,"has_issues":true,"team_id":'$READONLY_TEAM'}' -s https://api.github.com/orgs/${GITHUB_ORG_NAME}/repos` | |
ERRORS=`echo $RESPONSE | jq '.errors | length'` | |
MESSAGE=`echo $RESPONSE | jq 'has("message")'` | |
if [ $ERRORS -gt 0 ] || [ $MESSAGE = 'true' ]; then | |
echo "There was an error creating the new repository on github" | |
echo $RESPONSE | jq . | |
exit 1 | |
fi | |
git push --mirror [email protected]:${GITHUB_ORG_NAME}/${GITHUB_REPO_NAME}.git | |
# Update default branch to production if necessary | |
if [ -n "$3" ]; then | |
RESPONSE=`curl -u ${GITHUB_TOKEN}:x-oauth-basic -X PATCH -d '{"default_branch":"'$3'"}' -s https://api.github.com/orgs/${GITHUB_ORG_NAME}/${GITHUB_REPO_NAME}.git` | |
ERRORS=`echo $RESPONSE | jq '.errors | length'` | |
MESSAGE=`echo $RESPONSE | jq 'has("message")'` | |
if [ $ERRORS -gt 0 ] || [ $MESSAGE = 'true' ]; then | |
echo "There was an error updateing the default branch to ${3} on github" | |
echo $RESPONSE | jq . | |
exit 1 | |
fi | |
fi | |
cd .. | |
echo 'Returned to '`pwd` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment