fix git-mirror-org.sh

This commit is contained in:
Trevor Batley 2023-05-10 12:34:09 +10:00
parent 51594b5ee4
commit f8a1bd5bd7
2 changed files with 26 additions and 8 deletions

View File

@ -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
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?limit=1000?per_page=200" \
"$REMOTEGITEAHOST/api/v1/orgs/$1/repos?page=$page" \
-H 'accept: application/json' \
-H "Authorization: token $REMOTEACCESSTOKEN"
)
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
if [ $RESPONSE == "[]" ] ; then
# we have them all
break
else
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
echo "git-mirror-repo.sh ${repo} $1 $TARGETORG"
if [ $DEBUG ] echo "git-mirror-repo.sh ${repo} $1 $TARGETORG" ; fi
git-mirror-repo.sh ${repo} $1 $TARGETORG
done
fi
done

View File

@ -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