Skip to content

Instantly share code, notes, and snippets.

@shivanshs9
Created September 1, 2023 10:31
Show Gist options
  • Save shivanshs9/c6d18dcab359019a41083b3e62dde6aa to your computer and use it in GitHub Desktop.
Save shivanshs9/c6d18dcab359019a41083b3e62dde6aa to your computer and use it in GitHub Desktop.
Bitbucket to Github migration
#!/bin/bash
# How to use?
## bash gh_migrate_init.sh competition-service
GITHUB_ORG="coindcx-app"
JIRA="IDOPS-153"
SOURCE_FOLDER="coindcx-api-help"
prepare_repo() {
echo "Preparing service repo"
repo=$1
git clone git@bitbucket.org:JKLON/$repo
if [ $? -ne 0 ]; then
cd $repo
git checkout master
git pull
else
cd $repo
fi
git remote add github git@github.com:$GITHUB_ORG/$repo
git checkout --track origin/release/staging | git checkout --track origin/staging
git checkout -b $JIRA
cp -r ../$SOURCE_FOLDER/.github .github
cd ..
code -a $repo
}
prepare_infra() {
echo "Preparing Infra"
repo=$1
cd dcx-k8-infra
git checkout -b $JIRA-$repo
}
prepare_repo $1
prepare_infra ${2:-$1}
#!/bin/bash
# How to use?
## bash gh_migrate_pr.sh competition-service IDOPS-153-competition-service
set -eu
JIRA=IDOPS-153
BITBUCKET_REPO_OWNER="JKLON"
ENV="staging"
service=$1
infra_branch=$2
service_target_branch=${3:-release/$ENV}
BB_AUTH_STRING="shivanshs9:<PASSWORD>"
raise_pr() {
repo=$1
pr_title=$2
source=$3
target=$4
prid=$(curl https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${repo}/pullrequests \
-f -X POST \
-u "$BB_AUTH_STRING" \
-H 'Content-Type: application/json' \
-d '{
"title": "'"${pr_title}"'",
"state": "OPEN",
"description": "Automated PR creation process :-)",
"source": {
"branch": {
"name": "'"${source}"'"
}
},
"destination": {
"branch": {
"name": "'"${target}"'"
}
}
}' | jq '.id')
echo "https://bitbucket.org/${BITBUCKET_REPO_OWNER}/${repo}/pull-requests/$prid"
}
echo "Raising Infra PR"
# git push origin "$infra_branch"
raise_pr dcx-k8-infra "[$JIRA][$ENV]: Migrate $service to Graviton" "$infra_branch" master
# Push to github for test
cd $service && git push github $JIRA
echo "Raising service PR"
raise_pr "$service" "[$JIRA][$ENV]: Migrate pipeline to github/Graviton" "$JIRA" "$service_target_branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment