diff --git a/git-mirror-org.sh b/git-mirror-org.sh index 176e979..3f1bdff 100755 --- a/git-mirror-org.sh +++ b/git-mirror-org.sh @@ -49,21 +49,34 @@ REMOTEGITEAHOST=${remote_GITEAHOST} LOCALGITEAHOST=${local_GITEAHOST} TARGETORG= if [ $2 ] ; then TARGETORG=$2 ; fi +if [ $DEBUG ] ; then echo "TARGETORG=$TARGETORG" ; fi # check that the target organisation exists locally +if [ $DEBUG ] ; then echo "checking that $TARGETORG exists on $LOCALGITEAHOST" ; fi RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG) +if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi if [[ "$RESPONSE" != "200" ]] ; then echo "$TARGETORG does not exist on $LOCALGITEAHOST" exit 1 fi # get a list of repositories in the source organisation -RESPONSE=$(curl $curlsilent -X 'GET' \ - "$REMOTEGITEAHOST/api/v1/orgs/$1/repos?limit=1000?per_page=200" \ - -H 'accept: application/json' \ - -H "Authorization: token $REMOTEACCESSTOKEN" -) +for page in {1..10} ; do + if [ $DEBUG ] ; then echo "getting page $page of repos from $REMOTEGITHOST $1" ; fi + RESPONSE=$(curl $curlsilent -X 'GET' \ + "$REMOTEGITEAHOST/api/v1/orgs/$1/repos?page=$page" \ + -H 'accept: application/json' \ + -H "Authorization: token $REMOTEACCESSTOKEN" + ) + if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi -echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do - echo "git-mirror-repo.sh ${repo} $1 $TARGETORG" + if [ $RESPONSE == "[]" ] ; then + # we have them all + break + else + echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do + if [ $DEBUG ] echo "git-mirror-repo.sh ${repo} $1 $TARGETORG" ; fi + git-mirror-repo.sh ${repo} $1 $TARGETORG + done + fi done diff --git a/git-mirror-repo.sh b/git-mirror-repo.sh index ee9b3b5..2193999 100755 --- a/git-mirror-repo.sh +++ b/git-mirror-repo.sh @@ -52,15 +52,19 @@ TARGETORG=${local_USER} if [ $3 ] ; then TARGETORG=$3 ; fi # check that the TARGETORG exists +if [ $DEBUG ] ; then echo "checking if $TARGETORG exists on $LOCALGITEAHOST" ; fi RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG) +if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi if [[ "$RESPONSE" != "200" ]] ; then echo "$TARGETORG does not exist on $LOCALGITEAHOST" exit 1 fi # And check if this repo already exists on the target +if [ $DEBUG ] ; then echo "checking if $TARGETORG/$1 already exists on $LOCALGITEAHOST" ; fi RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1) -if [ "$RESPONSE" == "200" ] ; then +if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi +if [[ "$RESPONSE" == "200" || "$RESPONSE" == "307" ]] ; then echo "Repository $TARGETORG/$1 already exists on $LOCALGITEAHOST - cannot migrate" exit 1 fi @@ -94,6 +98,7 @@ if [ $DEBUG ] ; then echo $? $RESPONSE ; fi # And check if this repo is there if [ $DEBUG ] ; then echo "checking that $TARGETORG/$1 exists" ; fi RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1) +if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi if [ "$RESPONSE" == "200" ] ; then echo "Repository $TARGETORG/$1 has been created and mirrors $2/$1" else