From 7c642378171dde9fe8b576ccd6492f712a3fa675 Mon Sep 17 00:00:00 2001 From: nfgCodex Date: Wed, 9 Mar 2022 15:06:57 -0600 Subject: [PATCH] Minor changes to make work properly: * For loop was not evaluating correctly, was substituting "{1..2}" instead of the actual value * Added minor output to track what was going on * Removed break, as it was causing only the first item to sync --- bb2gh.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bb2gh.sh b/bb2gh.sh index 4365821..d02bb83 100755 --- a/bb2gh.sh +++ b/bb2gh.sh @@ -17,7 +17,7 @@ fi set -e mkdir -p repos # iterate 2 times -for page in {1..$pages} +for (( page=1; page<=$pages; page++ )) do repos=$(curl -s --user $BB_USERNAME:$BB_PASSWORD https://api.bitbucket.org/2.0/repositories/$BB_ORGANIZATION\?pagelen\=100\&page\=$page | jq ".values[].full_name" -r) for org_repo in $repos @@ -30,12 +30,16 @@ do git clone -q --bare git@bitbucket.org:$org_repo repos/$repo_name existCode=$(curl --write-out '%{http_code}' --silent --output /dev/null --user $GH_USERNAME:$GH_TOKEN https://api.github.com/repos/$org_repo) + # check for 404 if [ "$existCode" != "404" ]; then echo "Skipping as exists in github already" else - curl -s -u $GH_USERNAME:$GH_TOKEN https://api.github.com/orgs/$GH_ORGANIZATION/repos -d "{\"name\": \"$repo_name\", \"private\": true}" | jq ".html_url" -r + echo "Creating Github Repo" + resp=$(curl -s -X POST -u $GH_USERNAME:$GH_TOKEN https://api.github.com/orgs/$GH_ORGANIZATION/repos -d "{\"name\": \"$repo_name\", \"private\": true}") + echo $resp | jq ".html_url" -r cd repos/$repo_name + echo "Pushing to Github" git push --quiet --mirror git@github.com:$GH_ORGANIZATION/$repo_name.git cd ../.. fi @@ -45,7 +49,6 @@ do else echo "Skipping existing $repo_name" fi - break done done rm -rf repos