fix git-mirror-org.sh
This commit is contained in:
parent
51594b5ee4
commit
f8a1bd5bd7
@ -49,21 +49,34 @@ REMOTEGITEAHOST=${remote_GITEAHOST}
|
|||||||
LOCALGITEAHOST=${local_GITEAHOST}
|
LOCALGITEAHOST=${local_GITEAHOST}
|
||||||
TARGETORG=
|
TARGETORG=
|
||||||
if [ $2 ] ; then TARGETORG=$2 ; fi
|
if [ $2 ] ; then TARGETORG=$2 ; fi
|
||||||
|
if [ $DEBUG ] ; then echo "TARGETORG=$TARGETORG" ; fi
|
||||||
|
|
||||||
# check that the target organisation exists locally
|
# 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)
|
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG)
|
||||||
|
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
||||||
if [[ "$RESPONSE" != "200" ]] ; then
|
if [[ "$RESPONSE" != "200" ]] ; then
|
||||||
echo "$TARGETORG does not exist on $LOCALGITEAHOST"
|
echo "$TARGETORG does not exist on $LOCALGITEAHOST"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get a list of repositories in the source organisation
|
# get a list of repositories in the source organisation
|
||||||
RESPONSE=$(curl $curlsilent -X 'GET' \
|
for page in {1..10} ; do
|
||||||
"$REMOTEGITEAHOST/api/v1/orgs/$1/repos?limit=1000?per_page=200" \
|
if [ $DEBUG ] ; then echo "getting page $page of repos from $REMOTEGITHOST $1" ; fi
|
||||||
-H 'accept: application/json' \
|
RESPONSE=$(curl $curlsilent -X 'GET' \
|
||||||
-H "Authorization: token $REMOTEACCESSTOKEN"
|
"$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
|
if [ $RESPONSE == "[]" ] ; then
|
||||||
echo "git-mirror-repo.sh ${repo} $1 $TARGETORG"
|
# 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
|
done
|
||||||
|
@ -52,15 +52,19 @@ TARGETORG=${local_USER}
|
|||||||
if [ $3 ] ; then TARGETORG=$3 ; fi
|
if [ $3 ] ; then TARGETORG=$3 ; fi
|
||||||
|
|
||||||
# check that the TARGETORG exists
|
# 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)
|
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG)
|
||||||
|
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
||||||
if [[ "$RESPONSE" != "200" ]] ; then
|
if [[ "$RESPONSE" != "200" ]] ; then
|
||||||
echo "$TARGETORG does not exist on $LOCALGITEAHOST"
|
echo "$TARGETORG does not exist on $LOCALGITEAHOST"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# And check if this repo already exists on the target
|
# 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)
|
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"
|
echo "Repository $TARGETORG/$1 already exists on $LOCALGITEAHOST - cannot migrate"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -94,6 +98,7 @@ if [ $DEBUG ] ; then echo $? $RESPONSE ; fi
|
|||||||
# And check if this repo is there
|
# And check if this repo is there
|
||||||
if [ $DEBUG ] ; then echo "checking that $TARGETORG/$1 exists" ; fi
|
if [ $DEBUG ] ; then echo "checking that $TARGETORG/$1 exists" ; fi
|
||||||
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1)
|
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1)
|
||||||
|
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
||||||
if [ "$RESPONSE" == "200" ] ; then
|
if [ "$RESPONSE" == "200" ] ; then
|
||||||
echo "Repository $TARGETORG/$1 has been created and mirrors $2/$1"
|
echo "Repository $TARGETORG/$1 has been created and mirrors $2/$1"
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user